Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Xbox Lve Generator v3
Better way to get content via jQuery $.get()
Free CarTown Blue Points Generator and CarTown Templates
Steam Wallet Hack 2012
Diablo 3 error 37 & error 3006 fix
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
PAYPAL REMOVE ACCESS LIMITED ACCOUNT 100% Working
Pastable version of
Good way to output menu with submenu through a module?!
<pre class='prettyprint' language='ruby'>module Menus def self.getValidPositiveNumber input = gets.chomp while (input.to_i.to_s != input && input.to_f.to_s != input) do puts "Ogiltig data. Försök igen." input = gets.chomp end # Är talet större än 0? number = input.to_f if (number <= 0) puts "Du kan inte ange negativt värde." getValidPositiveNumber end return number end def self.get_valid_input(valid_options) input = gets.chomp # loopa tills ett giltigt värde angetts while (!valid_options.include?(input) && !valid_options.include?(input.to_i)) # både Range och Array har include? puts "Ogiltigt värde. Skriv in ett nytt alternativ mellan " + valid_options.inspect input = gets.chomp end return input end class Menu attr_reader :valid_options_range, :menu_string def initialize(valid_options_range, menu_string) @valid_options_range = valid_options_range @menu_string = menu_string end def do_menu_action(action) raise "Måste anropas i någon subklass!" end def to_s return @menu_string end end MAIN_MENU = <<END "---------------------------" Welcome to Ruby Camping! Menu 1. Checkin 2. Checkout 3. Lists 4. Economy 5. Exit What do you want to do? "---------------------------" END #if choice >= menu_options.length or choice < 0 #puts "Invalid choice" def make_menu_choice(choice) case choice when 1: $camping.check_in when 2: $camping.check_out when 3: $current_menu = LISTS_MENU when 4: $current_menu = ECONOMY_MENU when 5: exit end end LISTS_MENU = <<END "---------------------------" -- 1. List current guests -- -- 2. List all guests -- -- -- -- 0. Back to Main menu -- ------------------------------" END def make_menu_choice(choice) case choice when 1: $camping when 2: $camping.all_guests when 0: $current_menu = MAIN_MENU end end ECONOMY_MENU = <<END "---------------------------" -- 1. List current guests -- -- 2. List all guests -- -- -- -- 0. Back to Main menu -- ------------------------------" END end puts Menus::MAIN_MENU if Menus == 3 then LISTS_MENU = Lists_Menu.new elsif Menus == 4 then ECONOMY_MENU = Economy_Menu.new end __END__</pre> <a href="http://www.refactormycode.com/codes/1424-good-way-to-output-menu-with-submenu-through-a-module" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>