# Precedence of Private and Public methods

**URL:** <https://www.ruby-forum.com/t/precedence-of-private-and-public-methods/148702>\
**Category:** Ruby\
**Created:** [September 16, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/precedence-of-private-and-public-methods/148702 "2008-09-16T12:15:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 16, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/precedence-of-private-and-public-methods/148702/1 "2008-09-16T12:15:45Z")

</div>

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 : )

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 16, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/precedence-of-private-and-public-methods/148702/2 "2008-09-16T12:19:52Z")

</div>

> 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.
