Precedence of Private and Public methods

Hi!

Does anyone know what’s the precedence between private and public
methods.

Doing some tests I found that private methods have higher precendence
than public ones , but I don’t understand why.Any sugesstions?

Example:
class Class

def inherited(child)
p “public inherited”
end

private
def inherited(child)
p “private inherited”
end
end

Saving this code to a file and requiring it on irb does this:

Macintosh-5:~/programacion/ruby madtrick$ irb
irb(main):001:0> require “test”
=> true
irb(main):002:0> class Test
irb(main):003:1> end
“private inherited”
=> nil

On the other hand I don’t understand either, why te call to the
private inherited method works, as it’s a class method and should be
qualified by the name of it’s class, should’nt it?

Thanks in advance to anyone that gives a hand : )

def inherited(child)
p “public inherited”
end

private
def inherited(child)
p “private inherited”
end
end

This isn’t a precedence issue – the second method simply overwrites the
first since it comes later. Try moving the public one after the private
one
(and preface it with ‘public’) and see what happens.