Is there any pre build function by which we can read the whole file without using any loop? So far i have only come across the ones which output line one by one or character one by one.
Docs: http://ruby-doc.org/core/classes/IO.html
quantumSoup
2010-07-25 08:13:37
+1
A:
File.readlines("filename")
This is also a great method to read everything from a file and break split on carriage returns. The return is an Array with one line per element.
Nick
2010-07-25 11:40:46
More specifically, `readlines` splits on the internal variable `$/`, which defaults to "\n". You can temporarily reset `$/`, however, and read files into chunks delimited in other ways, too.
Telemachus
2010-07-25 12:32:10