From: Leonard Chin Date: 2007-06-01T20:59:39+09:00 Subject: Re: Access Modifiers On 6/1/07, Vin Raja wrote: > THE HITCH > > In first case it appears that that private declaration had no effect, > thus the textual position matters here; If this is really so, can anyone > explain why?? Note first that private is not a declaration. It is a method call. In your case, note that to_s is actually defined on Object already. In case 1, the to_s inherited from Object is turned private, then gets overridden. When you override it, it is no longer private. In case 2, you override to_s first and then make it private, leaving it private. Keep in mind that this happens because you are overriding an existing method! You would get different behaviour if it wasn't an existing method Play around in irb more :) > > AND > > In second case why the private declaration had no effect on > puts p > when in fact (this is what i infer) it uses the same method which > puts p.to_s > uses. p doesn't call to_s. If you look at the docs, it actually calls Object#inspect which then uses to_s -> which is OK, because they are methods on the same object! Kernel.p docs: http://corelib.rubyonrails.org/classes/Kernel.html#M002080