Skip to content

Instantly share code, notes, and snippets.

@ilyanep
Created July 14, 2010 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ilyanep/475064 to your computer and use it in GitHub Desktop.
Save ilyanep/475064 to your computer and use it in GitHub Desktop.
# Suppose I want to the user to enter names one at a time, until the user enters a blank line,
# then tell each name that they're awesome. In a typical programming language, my first instinct
# would be to do:
while (name = gets.chomp) != ""
puts name + ", you are so awesome"
# or perhaps alternatively, to get the names to print afterwards
names = Array.new
while (name = gets.chomp) != ""
names.push name
end
names.each do |nom|
puts "#{nom}, you are so awesome"
end
# But this is a very C way of doing things, and Ruby is supposed to be more elegant. How would you
# do this? Seems like there has to be a way of avoiding using a while loop, and it's probably actually
# really easy, but I'm just being dumb slash don't know Ruby that well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment