#Slurping popen
text = IO.popen("ls") {|f| f.read}
#Slurping an ordinary file
text = IO.read("file.txt")
Refactorings
No refactoring yet !
Adam
January 14, 2009, January 14, 2009 16:06, permalink
Take your pick.
IO.popen('ls').read
IO.read('| ls')
andrewjgrimm
January 18, 2009, January 18, 2009 08:54, permalink
The former would leave a file handle open, but the latter looks good.
Is there an equivalent of IO.read for popen, or is calling f.read in a block the tightest way to do it?