From: Benjohn Barnes Date: 2007-04-16T05:27:24+09:00 Subject: Re: translate Perl diamond operator to Ruby On 15 Apr 2007, at 19:40, Ken Bloom wrote: > On Mon, 16 Apr 2007 03:06:58 +0900, Chad Perrin wrote: > >> Over the years, I've found the following to be an excellent way to >> whip >> up quick, very useful Perl scripts: >> >> #!/usr/bin/perl >> >> while(<>) { >> # do stuff . . . >> } >> >> Is there an equivalent idiom in Ruby? So far as I'm aware, >> there's no >> catch-all diamond operator in Ruby that allows one to create a >> default >> input behavior for a script that accepts either a filename or piped >> output of another command the way this works in Perl. I certainly >> hope >> there's an equivalent, though. > > ARGF.each do |line| > # do stuff > end What _is_ ARGF? I've printed it's class, but apparently it is: > irb(main):003:0> ARGF.class > => Object ... an Object.