Bug #12216
closedClass inherited Singleton method exclude argument from protected method accessing
Description
Dear Ruby Lang developers.
I would like to ask about why the following code can work?
Or is it a valid scenario and "as expected" behavior to ignore public call on a protected method.
Thank you guys for the brilliant!
class A
class << self
def inherited(klass)
p klass.protected_method_call
end
protected
def protected_method_call
self.to_s
end
end
end
class B < A
end
# output: "B"
Updated by nobu (Nobuyoshi Nakada) about 8 years ago
- Description updated (diff)
- Status changed from Open to Rejected
Expected behavior.
In the inherited
method, self
and klass
are A
and B
respectively, which are instances of Class
.
Protected methods can be called from a same class instance.
Updated by adamluzsi (Adam Luzsi) about 8 years ago
Nobuyoshi Nakada wrote:
Expected behavior.
In theinherited
method,self
andklass
areA
andB
respectively, which are instances ofClass
.
Protected methods can be called from a same class instance.
Thank you very much!
My mistake, I mixed up with the private scope.
I'm terrible sorry for this.
Best regards,
Adam L.
Updated by adamluzsi (Adam Luzsi) about 8 years ago
Nobuyoshi Nakada wrote:
Protected methods can be called from a same class instance.
So far I though, A and B is a different class instance, just they are in inheritance relationship.
But I see now,
class instance != object instance
class instance is based on inheritance