01bbb59a1c3ef9960f25a97afe7e920f

Is there an equivalent of IO.read for popen, or is calling f.read in a block the tightest way to do it?

#Slurping popen
text = IO.popen("ls") {|f| f.read}

#Slurping an ordinary file
text = IO.read("file.txt")

Refactorings

No refactoring yet !

A8d3f35baafdaea851914b17dae9e1fc

Adam

January 14, 2009, January 14, 2009 16:06, permalink

1 rating. Login to rate!

Take your pick.

IO.popen('ls').read

IO.read('| ls')
01bbb59a1c3ef9960f25a97afe7e920f

andrewjgrimm

January 18, 2009, January 18, 2009 08:54, permalink

1 rating. Login to rate!

The former would leave a file handle open, but the latter looks good.

832ed6ace46d61032151f4e1864c057f

Dmitry Polushkin

January 22, 2009, January 22, 2009 10:01, permalink

No rating. Login to rate!
%x[ls]

Your refactoring





Format Copy from initial code

or Cancel