Create a text file with ruby

M

Marcelo Junior

How make for create a text file using ruby? And how a make for updated
this text file?
 
H

Harold Hausman

How make for create a text file using ruby? And how a make for updated
this text file?

# Hello. Consider this code:
File.open( "testfile.txt", "w" ) do |the_file|
the_file.puts "I'm a line in the text file!"
end

# hope that helps,
# -Harold
 
T

Tim Becker

File inherits from IO, you'll probably want to read that as well
(http://www.rubycentral.com/book/ref_c_io.html). Also, please consider
reading an introductory text on Ruby, because the questions you're
asking are very elementary and covered in any tutorial text.

The Ruby Book (http://www.rubycentral.com/book/) that the
documentation we linked to above is from, would be an excellant start.
There's a whole chapter called "Basic Input and Output" that should
contain enough infos about files to get you started.

Take care,
-Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,236
Messages
2,571,185
Members
47,820
Latest member
HortenseKo

Latest Threads

Top