Ruby – What’s a reasonable way to read an entire text file as a single string


I am sure this is an easy one; I just couldn't find the answer immediately from Google.

I know I could do this (right?):

text = "" do |line|
    text += line

# Do something with text

But that seems a bit excessive, doesn't it? Or is that the way one would do it in Ruby?

Best Solution is what you're looking for.
File is a subclass of IO, so you may as well just use:

text =

Can't get more intuitive than that.