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

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

$ irb
irb(main):001:0> File.read('readme.md')
=> "hello world"
+4
source share
3 answers

Documented:

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

The method is inherited from IO, though.

+8
source

Use Ruby to research:

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  
+6
source

:

File.method(:read)
#=> #<Method: File(IO).read>

['array'].method(:flatten)
#=> #<Method: Array#flatten>

, - , .

Class.method.

, , Class#method.

, #<Method: File(IO).read> , read - , IO File.

, Ruby ( C), Method#source_location:

require 'set'
Set.new.method(:replace).source_location
#=> ["~/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/set.rb", 142]

, Set#replace Ruby 142.

If you use PRY as an alternative to IRB, you can even use:

show-source Set#replace
#=> 
From: /home/ricou/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/set.rb @ line 142:
Owner: Set
Visibility: public
Number of lines: 10

def replace(enum)
  if enum.instance_of?(self.class)
    @hash.replace(enum.instance_variable_get(:@hash))
  else
    clear
    merge(enum)
  end

  self
end
+4
source

Source: https://habr.com/ru/post/1663771/


All Articles