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 TogetherConsider the following ruby one-lineer
ruby -e 'p ARGF.inject(0) { |sum, line| line.split[1].to_i + sum }'
Breaking it down, it …
ARGF.inject(0))line.split)[1]).to_i)+ sum)p)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 :)