Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions random_menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# array of food descriptors
descriptor = [
"hot",
"crispy",
"chilled",
"spicy",
"sour",
"cheesy",
"fresh",
"vegetarian",
"aged",
"pickled"
]

# array of cooking styles
cooking_style = [
"steamed",
"fried",
"stir-fried",
"seared",
"sous-vide",
"terrine of",
"baked",
"boiled",
"scrambled",
"blended",
]

# array of foods
food = [
"salmon",
"chicken breast",
"lamb",
"cous-cous",
"pork",
"seafood",
"shrimp",
"sirloin",
"pudding",
"omelet"
]

# random menu generator loop numbering menu items 1 - 10 and taking a random element from descriptor, cooking_style, and foods arrays
(1..10).each {
|n| puts "#{n}. #{descriptor.sample} #{cooking_style.sample} #{food.sample}"
}
Copy link

@droberts-sea droberts-sea Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nitpick: we'd like to encourage you to use do...end rather than curly braces, and the iteration variable (|n|) should go on the first line (think of it like a method parameter). So this loop would be rewritten as:

(1..10).each do |n|
  puts "#{n}. #{descriptor.sample} #{cooking_style.sample} #{food.sample}"
end

BTW, using (1..10).each is a clever way to get around 10.times starting at zero. Nice work.