Close

Ruby Recipe – Store contents of a file in a variable

$ cat testscript.rb
#!/usr/bin/env ruby

data = File.read("/tmp/testfile.txt")
puts data
$
$ cat /tmp/testfile.txt
Hello!
here is some content.
Goodbye.
$
$ ./testscript.rb
Hello!
here is some content.
Goodbye.
$