From: Patrick Hurley Date: 2006-05-04T22:48:30+09:00 Subject: Re: class methods and protected instance methods On 5/1/06, Gregory Seidman wrote: > I would have thought that a class method context would be able to call > protected methods on an instance of that class. That does not seem to be > the case: > > class Foo > def self.create_with_magic > newfoo = new() > newfoo.init_magic > return newfoo > end > > def initialize > # no magic here > end > > protected > > def init_magic > # something magical > end > end > > foo = Foo.create_with_magic #this will raise an exception > > Is this just an oversight? A bug? Is there a rationale for it that I'm not > seeing? I'm not looking for a workaround; I've already found a better way > of doing what brought this to my attention. I am just looking for an > explanation. > > --Greg > > > This is what is expected. Ruby is not C++/Java and its object model is quite different. In particular as Class objects are first class objects, they do not bestow any special access rights to other objects, including instances of themselves. pth