{ |one, step, back| }

Today's One Liner
18 Sep 05 - http://onestepback.org/index.cgi/Tech/Ruby/OneMillionServed.red

I don’t usually talk must about one-liners, but here’s one I used today.

ARGF and inject ... Two Great Tastes that Taste Great Together

Consider the following ruby one-lineer

ruby -e 'p ARGF.inject(0) { |sum, line| line.split[1].to_i + sum }'

Breaking it down, it …

In short, it sums up the numbers in the second column of a text file.

Cool. Now combine it with another one-liner …

lynx -dump http://gems.rubyforge.org/stats.html \
  | ruby -e 'p ARGF.inject(0) { |s,t| t.split[1].to_i + s }'

And you get the result …

1005821

... which is the number of gems served by RubyForge to date.

Over 1 million gems served :)