Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I read Ruby's File.open function?

Tags:

ruby

I'm going through "Learn Ruby the Hard Way" and I can't get my Windows command prompt to display the docs for: ri File.open

It just gives me an error:

ArgumentError: wrong number of arguments (0 for 1..3)

I'm currently on exercise 16: http://ruby.learncodethehardway.org/book/ex16.html

And the extra credit says: If you open the file with 'w' mode, then do you really need the target.truncate()? Go read the docs for Ruby's File.open function and see if that's true.

where can I see the docs for the File.open function?

like image 704
Gregg Avatar asked Nov 22 '25 13:11

Gregg


1 Answers

Read the documentation of IO, File's parent class. It describes the file opening modes you mentioned in your question. Here's the description for the w opening mode:

"w"  Write-only, truncates existing file
     to zero length or creates a new file for writing.

So no, you don't really need to call target.truncate if you open the file in w mode.

like image 102
Matheus Moreira Avatar answered Nov 25 '25 04:11

Matheus Moreira