From: Brian Adkins Date: 2007-08-18T13:09:59+09:00 Subject: Re: Help with Arrays... On Aug 17, 2:04 pm, William James wrote: > The original poster wants the loop to end when the user presses > > without entering any text. How about this? > > words = [] > while line = gets and line.chomp! != "" > words << line > end Might as well simply evaluate the assignment expression directly: words = [] while (line = gets.chomp) != '' words << line.chomp end puts words.sort While that fulfills the original spec, I agree with Dan's comment regarding -D or EOF. It would be nice to handle that to allow piping a file of words to the program. Before I noticed Robert's post, I came up with the following: puts ARGF.inject([]) {|memo,obj| memo << obj}.sort although fun, it's way too verbose. I ended up shortening Robert's to this: puts ARGF.sort If you don't want to create a .rb file, just: ruby -e 'puts ARGF.sort' :)