Skip to content

Instantly share code, notes, and snippets.

@margieI
Created July 15, 2015 15:11
Show Gist options
  • Save margieI/f1324bd7547d7ffe9d62 to your computer and use it in GitHub Desktop.
Save margieI/f1324bd7547d7ffe9d62 to your computer and use it in GitHub Desktop.
def fav_foods
# code for this method goes in here
food_array = Array.new
3.times do
puts "Name a favorite food."
food_array << gets.chomp
end
p food_array
puts "Your favorite foods are #{food_array.join(", ")}"
food_array.each do |food| # do something to each element in food_array; that element is to be referred to as food
puts "I like #{food} too!" # the thing we are doing
end # ends the loop
end
fav_foods
#The above code 12,13,14 is exactly the same thing with this.
#food_array.each { |food| puts "I like #{food} too!" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment