How do I write to a file in Ruby?

Viewed 3579

There are many SO answers for this such as "How to write to file in Ruby?", but I am missing a point with a path to file:

I have a file structure like this:

├── test.txt
├── write_to_file.rb

and "write_to_file.rb" has the following content:

 File.open('test.txt', 'w') { |file| file.write('hello') }
 # tried ('./test.txt','w') ..as well.

How do I write some content to test.txt file from another write_to_file.rb?

2 Answers
Related