Project

General

Profile

Actions

Bug #12131

closed

Should defining singleton_method_added call itself?

Added by Eregon (Benoit Daloze) about 8 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[ruby-core:74081]

Description

This seems surprising:

obj = Object.new
def obj.singleton_method_added(n)
  p n
end
def obj.new_singleton_method; end

outputs

:singleton_method_added
:new_singleton_method

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

Given that singleton_method_added is called after the method is added and not before, I think the current behavior makes sense and do not think it is the bug. The same behavior exists for method_added:

module A
  extend self
  def method_added(n) p n end
end

outputs:

:method_added

Updated by Eregon (Benoit Daloze) almost 5 years ago

  • Status changed from Open to Closed

Right, it makes sense with the current semantics.
I think this is surprising though, and possibly causing bugs for people expecting the method to be called only for methods defined after method_added/singleton_method_added.
However, since no one seems bothered too much, let's close this.

Actions

Also available in: Atom PDF

Like0
Like0Like0