I just added this to my .irbrc:
# Add the unix-style pipe command to strings
class String
def |(cmd)
IO.popen(cmd, 'r+') do |pipe|
pipe.write(self)
pipe.close_write
pipe.read
end
end
end
Usage:
"foo\nbar\nbaz" | 'sort' # => "bar\nbaz\nfoo"
Feel free to nab it for Utility Belt if you think others might find it useful.
--
Avdi