From: Pete Date: 2006-06-07T04:49:19+09:00 Subject: Re: Instance methods can't call protected class methods? where's the problem? class Test protected def self.call_me puts "static and protected" end public def invoke_me puts "try to call" Test.call_me # this will _not_ work: self.call_me puts "done" end end t = Test.new t.invoke_me > try to call > static and protected > done Sean Hermany schrieb: > I am trying to understand this behavior. > > >From page 356 of the Pickaxe (2nd ed): > > Protected. Can be invoked only by objects of the defining class and its > subclasses. > > If I have > > class Foo > ... > end > > f = Foo.new > > Is f not an "object of the defining class"? If so, why should an > instance method of Foo not be able to call a protected class method? > > I'm not looking for an answer of the form "because in class scope, > self.class.type.object.class # => Object, however in *instance* scope" > etc. Logically, why should it be this way? > > In C++ it makes sense that a static class method cannot call an > non-static method, since static methods exist even when there are no > objects of the class in existence. However, they do not limit you on the > reverse and prevent a non-static method from calling a static method. > >