[["", STDIN]] : ARGV.lazy.map { |filename| [filename, File.open(filename)] }).map { |filename, file| "%4d %4d %4d %s\n" % [*file.lines.lazy.map { |line| [1, line.split.length, line.length] }.inject([0, 0, 0]) { |(lc, wc, cc), (l, w, c)| [wc + w, lc + l, cc + c] }, filename] }.each(&:display) by @shugomaeda http://shugomaeda.blogspot.com/2012/03/ enumerablelazy-and-its-benefits.html