Does the Ruby method search begin at the bottom of the class and rise up, or above, and go down?

I'm starting to learn more about the Ruby object model and trying to understand how the methods are found.

As I understand it, an object searches for a method, checking its own class (going to the right), and if the method is not found there, it goes up the hierarchy of the ancestors.

What am I confused, though ... when he looks into the class, does he read each method from bottom to top or top to bottom?

I think of the first. But if this is true, then it puts me as contrary to what I always understood about how programs are read / interpreted - from top to bottom.

Can someone confirm my understanding of this. Thank.

0
source share
1 answer

later ads override earlier ones -

class Foo
  def hello
    'hello first'
  end

  def hello
    'hello second'
  end
end

f = Foo.new

puts f.hello # hello second
+3
source

All Articles