-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Menu class (User Defined Class) | ||
|
||
class Menu | ||
attr_reader:length_quit | ||
|
||
def initialize(*menu_args) | ||
@menu_args = menu_args | ||
@length_quit = length_quit | ||
end | ||
|
||
def menu_get_choice | ||
@menu_args.each_with_index do |item, index| | ||
puts "#{index + 1}. #{item}" | ||
|
||
end | ||
print "Please place your order" | ||
user_choice = gets.to_i | ||
return user_choice | ||
|
||
end | ||
|
||
menu = Menu.new("PIZZA", "BURGER", "SANDWICH", "JUICE", "QUIT") | ||
|
||
while ((choice = menu.menu_get_choice) != menu.length_quit) | ||
case choice | ||
when 1 | ||
puts "Please Wait!! Your order for PIZZA has been placed!" | ||
when 2 | ||
puts "Please Wait!! Your order for BURGER has been placed!" | ||
when 3 | ||
puts "Please Wait!! Your order for SANDWICH has been placed!" | ||
when 4 | ||
puts "Please Wait!! Your order for JUICE has been placed!" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Random numbers in Ruby | ||
|
||
puts rand # 0 - 0.99 | ||
|
||
puts rand*10 # 0 - 0.99 | ||
|
||
puts (rand*10).to_i # Integer | ||
|
||
puts (rand*30 + 10).to_i # Integer between 10 to 30 | ||
|
||
puts rand(10) #0 - 9 | ||
|
||
puts rand(10)+1 | ||
|
||
puts rand(0..10) # Include 10 | ||
|
||
puts rand(0...10) # Exclude 10 | ||
|
||
puts (0..5).map{rand(0..10)} | ||
|
||
puts (0...5).map{rand(0..10)} | ||
|
||
puts (0...5).map{rand(0..20)} | ||
|
||
|
||
|
||
# srand | ||
|
||
srand 1234 | ||
|
||
puts rand | ||
|
||
srand 1234 | ||
|
||
puts rand | ||
|
||
|
||
srand 1234 | ||
|
||
puts rand, rand | ||
|
||
srand 1234 | ||
|
||
puts rand, rand | ||
|
||
|
||
srand 1234 | ||
|
||
puts rand(10), rand(100) | ||
|
||
srand 1234 | ||
|
||
puts rand(10), rand(100)# Random numbers in Ruby | ||
|
||
puts rand # 0 - 0.99 | ||
|
||
puts rand*10 # 0 - 0.99 | ||
|
||
puts (rand*10).to_i # Integer | ||
|
||
puts (rand*30 + 10).to_i # Integer between 10 to 30 | ||
|
||
puts rand(10) #0 - 9 | ||
|
||
puts rand(10)+1 | ||
|
||
puts rand(0..10) # Include 10 | ||
|
||
puts rand(0...10) # Exclude 10 | ||
|
||
puts (0..5).map{rand(0..10)} | ||
|
||
puts (0...5).map{rand(0..10)} | ||
|
||
puts (0...5).map{rand(0..20)} | ||
|
||
|
||
|
||
# srand | ||
|
||
srand 1234 | ||
|
||
puts rand | ||
|
||
srand 1234 | ||
|
||
puts rand | ||
|
||
|
||
srand 1234 | ||
|
||
puts rand, rand | ||
|
||
srand 1234 | ||
|
||
puts rand, rand | ||
|
||
|
||
srand 1234 | ||
|
||
puts rand(10), rand(100) | ||
|
||
srand 1234 | ||
|
||
puts rand(10), rand(100) |