From: Jim Weirich Date: 2006-06-07T05:13:29+09:00 Subject: Re: Instance methods can't call protected class methods? Sean Hermany wrote: [... example elided ...] > 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. So, I'm guessing that saying "Because f and Foo have different defining classes" isn't the answer you are looking for, because you go on to say: > Logically, why should it be this way? So you are looking for the reason the protected rule was chosen, rather than an explaination of the rule itself. Hmm, only Matz himself can only answer that question definitively, however, I can make some guesses. The first reason is a complexity/benefit tradeoff. The rule currently is that only instances of the same class (or related subclass) can call protected methods. Your suggestion would add additional cases to the rule. Is the benefit gained from the extra conditions worth the extra complexity of the rule? Perhaps not. There may also be a runtime cost to allowing additional classes to call protected methods. Since determining if a protected method call is valid involves some runtime checking, making the list of possible calling classes larger might impact performance. Note the heavy use of "may" and "might" in this paragraph, I'm no expert on Ruby internals. -- Jim Weirich -- Posted via http://www.ruby-forum.com/.