2

How would this be written to be on a single line?

in_file = open(from_file)
indata = in_file.read
chilledheat
  • 33
  • 1
  • 6
  • 1
    indata = File.open(from_file).read. from_file - path to file – Ilya Apr 01 '16 at 15:42
  • 2
    Some examples here: http://stackoverflow.com/questions/5545068/what-are-all-the-common-ways-to-read-a-file-in-ruby – orde Apr 01 '16 at 15:47
  • "How would this be written to be on a single line?" – Use semicolon instead of newline. Always works, you can write *any* Ruby program, no matter how complex, in one single line. – Jörg W Mittag Apr 01 '16 at 23:32

2 Answers2

6
File.read("/path/to/file")

It will read whole file content and return it as a result.

SunnyMagadan
  • 1,729
  • 13
  • 12
1

open("README.md").read

For very small file, this is acceptable.

dvxam
  • 584
  • 3
  • 11