Friday, February 19, 2010

Read a File to a String in Ruby

Reading a File into a String in Ruby is just:
  s = File.open('filename', 'r') { |f| f.read } 
(Thanks to Håkan Rönngren for that- got rid of the cruft.)

2 comments:

Håkan Rönngren said...

s = File.open('filename', 'r') { |f| f.read }

Gary S. Weaver said...

Good point. Will update. Thanks!