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"
Use the Ruby File. dirname method. For me, File. dirname("/a/b/c/d") correctly returns /a/b/c but File.
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.
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.
It is documented:
http://ruby-doc.org/core-2.3.3/IO.html#method-c-read
The method is inherited from IO
though.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With