What's a reasonable way to read an entire text file as a single string? What's a reasonable way to read an entire text file as a single string? ruby ruby

What's a reasonable way to read an entire text file as a single string?


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

text = File.read(path)

Can't get more intuitive than that.


What about IO.read()?

Edit: IO.read(), as an added bonus, closes the file for you.