Forum: Ruby Create a text file with ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ccf0f43fe1adcaf0992e9576f0eb4494?d=identicon&s=25 Marcelo Junior (mr_brownstone)
on 2007-03-05 03:55
How make for create a text file using ruby? And how a make for updated
this text file?
7f891fbe8e3bae7f9fe375407ce90d9d?d=identicon&s=25 Harold Hausman (Guest)
on 2007-03-05 04:04
(Received via mailing list)
On 3/5/07, Marcelo Junior <marcelo.machado.jr@gmail.com> wrote:
> 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
4371f8fa1c3574e74d8f88c77d23e7d7?d=identicon&s=25 Harry (Guest)
on 2007-03-05 04:13
(Received via mailing list)
On 3/5/07, Marcelo Junior <marcelo.machado.jr@gmail.com> wrote:
> How make for create a text file using ruby? And how a make for updated
> this text file?
>

http://www.rubycentral.com/book/ref_c_file.html#File.new


Harry
Ccf0f43fe1adcaf0992e9576f0eb4494?d=identicon&s=25 Marcelo Junior (mr_brownstone)
on 2007-03-05 17:01
And how make for get the text of text file?
62002cee15efcf4628cd7efc19425a07?d=identicon&s=25 Tim Becker (Guest)
on 2007-03-05 17:10
(Received via mailing list)
On 3/5/07, Marcelo Junior <marcelo.machado.jr@gmail.com> wrote:
> And how make for get the text of text file?

Also described here:
http://www.rubycentral.com/book/ref_c_file.html#File.new
Ccf0f43fe1adcaf0992e9576f0eb4494?d=identicon&s=25 Marcelo Junior (mr_brownstone)
on 2007-03-05 17:13
Tim Becker wrote:
> On 3/5/07, Marcelo Junior <marcelo.machado.jr@gmail.com> wrote:
>> And how make for get the text of text file?
>
> Also described here:
> http://www.rubycentral.com/book/ref_c_file.html#File.new

But this not have how get the contet of file. How make this?
62002cee15efcf4628cd7efc19425a07?d=identicon&s=25 Tim Becker (Guest)
on 2007-03-05 17:30
(Received via mailing list)
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
This topic is locked and can not be replied to.