1

I have a txt file stored in file system. I want to read the content of that file in single go and assign it to a varialble. whichever function i try i get this error

Error: undefined method 'root' for #

How can i do this?

Priya Saini
  • 109
  • 13

1 Answers1

1

You can read a file in Ruby using the File.read function:

s = File.read 'your_file_name.txt'

Now, the variable s will have the file's content.

Douglas Lise
  • 1,466
  • 1
  • 20
  • 46