Bug #2375
closedprotected singleton methods can be called from other instances
Description
=begin
It seems that protected singleton methods of an object can be called from other instances of the class of the object.
class Foo
end
FOO = Foo.new
class << FOO
protected
def bar
puts "bar"
end
end
class Foo
def baz
FOO.bar
end
end
FOO.baz
Foo.new.baz # CRuby does not raise NoMethodError, but IronRuby does.
On IronRuby, Foo.new.baz raies NoMethodError, and I guess it's more reasonable than the behavior of CRuby. I have attached a patch.
However, I haven't been able to find any use cases of protected singleton methods.
=end
Files
Updated by matz (Yukihiro Matsumoto) over 14 years ago
=begin
Hi,
In message "Re: [ruby-core:26761] [Bug #2375] protected singleton methods can be called from other instances"
on Mon, 16 Nov 2009 14:26:23 +0900, Shugo Maeda redmine@ruby-lang.org writes:
|On IronRuby, Foo.new.baz raies NoMethodError, and I guess it's more reasonable than the behavior of CRuby. I have attached a patch.
|
|However, I haven't been able to find any use cases of protected singleton methods.
Agreed. But consistency matters when there's no side effect. Please
check it in to the repository.
matz.
=end
Updated by shugo (Shugo Maeda) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
This issue was solved with changeset r25796.
Shugo, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end