Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is File.read('/path/to/file') not in Ruby docs?

Tags:

ruby

Why is the File.read method not documented in http://ruby-doc.org/core-2.3.3/File.html when it clearly exists:

$ irb
irb(main):001:0> File.read('readme.md')
=> "hello world"
like image 901
Riley Guerin Avatar asked Dec 14 '16 18:12

Riley Guerin


People also ask

How do you find the file path in Ruby?

Use the Ruby File. dirname method. For me, File. dirname("/a/b/c/d") correctly returns /a/b/c but File.

How do I read a file in Ruby?

Opening a File in Ruby There are two methods which are widely used − the sysread(n) and the read() method. The open method is used to open the file, while the sysread(n) is used to read the first "n" characters from a file, and the read() method is used to read the entire file content.

What is __ FILE __ Ruby?

In Ruby, the Windows version anyways, I just checked and __FILE__ does not contain the full path to the file. Instead it contains the path to the file relative to where it's being executed from.


2 Answers

It is documented:

http://ruby-doc.org/core-2.3.3/IO.html#method-c-read

The method is inherited from IO though.

like image 86
undur_gongor Avatar answered Sep 19 '22 23:09

undur_gongor


Use Ruby to investigate:

File.methods.include? :read
 #=> true 
File.methods(false).include? :read                                                                    
 #=> false 
File.ancestors
 #=> [File, IO, File::Constants, Enumerable, Object, Kernel, BasicObject] 
IO.methods(false).include? :read
 #=> true  
like image 32
Sagar Pandya Avatar answered Sep 17 '22 23:09

Sagar Pandya