From: Robert Klemme Date: 2006-07-09T21:01:19+09:00 Subject: Re: Sweet Lord! 2006/7/8, Daniel Schierbeck : > Why haven't I thought of this before? > > class Terminal > include Enumerable > > def each(&block) > while input = gets > block.call(input.chomp) > end > end > end > > terminal = Terminal.new > > # terminate the loop with ctrl-d, or whatever works for you. > terminal.entries > terminal.map{|line| line.to_sym} > terminal.inject(""){|str, line| str << line} > > > > Yet another epiphany. Thank you, Ruby. Is chomp really worth a new class? Note that you can do all of this already with an IO: $ ruby -e 'STDIN.each {|line| p line}' dd "dd\n" ff "ff\n" $ ruby -e 'p STDIN.entries' dd ff ["dd\n", "ff\n"] $ ruby -e 'p STDIN.map {|line| line.inspect}' ddd sss ["\"ddd\\n\"", "\"sss\\n\""] Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/