Skip to content

Instantly share code, notes, and snippets.

@saintmedusa
Created February 4, 2020 01:15
Show Gist options
  • Save saintmedusa/56b3a65244eb008da36a0e002730b156 to your computer and use it in GitHub Desktop.
Save saintmedusa/56b3a65244eb008da36a0e002730b156 to your computer and use it in GitHub Desktop.
# create hash of three different menu word arrays
menu = Hash.new
# create a hash that is a mirror of the menu hash.
rand_selects = Hash.new
# prompt user for menu size
puts "How many menu items would you like? minumum 1, maximum 10."
MENU_SIZE = gets.chomp.to_i
# test input
while MENU_SIZE > 10 || MENU_SIZE < 1
puts "Oops, please enter a number between 1 and 10:"
MENU_SIZE = gets.chomp.to_i
end
# fill Menu words hash with arrays
menu[:descr] = ["creamy", "spicey", "layered", "succulent", "cheesy", "grilled", "herbed", "roasted", "pan-fried",
"citrus"]
menu[:prep] = ["mixed vegetable", "sesame", "chicken", "yam", "mushroom", "ginger", "squash", "beef", "tofu", "broccoli"]
menu[:main] = ["burrito", "rice", "soup", "sandwich", "dumplings", "stir-fry", "grain bowl", "casserole", "beans",
"fish"]
# initialize arrays of rand_selects hash
rand_selects[:descr] = Array.new
rand_selects[:prep] = Array.new
rand_selects[:main] = Array.new
# Populate the rand_selects arrays with unique index numbers to use to pull unique
# menu words from the menu hash. Test the rand_selects array as it is filled. Print
# the menu selections as unique words are selected.
(MENU_SIZE).times do |i|
rand_selects[:descr][i] = rand(0..9)
until rand_selects[:descr].length == rand_selects[:descr].uniq.length
rand_selects[:descr][i] = rand(0..9)
end
rand_selects[:prep][i] = rand(0..9)
until rand_selects[:prep].length == rand_selects[:prep].uniq.length
rand_selects[:prep][i] = rand(0..9)
end
rand_selects[:main][i] = rand(0..9)
until rand_selects[:main].length == rand_selects[:main].uniq.length
rand_selects[:main][i] = rand(0..9)
end
puts (i + 1).to_s + ". " + menu[:descr][rand_selects[:descr][i]] + " " + menu[:prep][rand_selects[:prep][i]] + " " + menu[:main][rand_selects[:main][i]]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment