Skip to content

Instantly share code, notes, and snippets.

@andymatuschak
Forked from ilyanep/some looping stuff.rb
Created July 14, 2010 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymatuschak/475072 to your computer and use it in GitHub Desktop.
Save andymatuschak/475072 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.
# Yeah, I don't have really a better way of doing that, and that bothers me. I'd do:
a = []
until (str = gets.chomp?).empty?
a << str
end
# The key thing that keeps you from using a standard HOM is that you don't know the
# number of elements you're going to have off the bat.
# Generators are a pattern for dealing with this: http://en.wikipedia.org/wiki/Generator_(computer_science)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment