Project

General

Profile

Actions

Bug #2375

closed

protected singleton methods can be called from other instances

Added by shugo (Shugo Maeda) over 14 years ago. Updated about 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
1.9.2dev
Backport:
[ruby-core:26761]

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

protected_singleton_method.diff (842 Bytes) protected_singleton_method.diff a patch to forbid protected singleton calles from other instances shugo (Shugo Maeda), 11/16/2009 02:26 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4106: 1.9.2 regression - invoking protected singleton methodsRejected12/01/2010Actions
Actions #1

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 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

Actions #2

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

Actions

Also available in: Atom PDF

Like0
Like0Like0