[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Precedence of Private and Public methods

refugallo

9/16/2008 10:10:00 AM

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

James Coglan

9/16/2008 10:12:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

> 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



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.