Issue #5015 has been updated by Lazaridis Ilias.

File method_added_callback.diff added

Attached a simple patch, which avoids the method_added callback for 

VM_METHOD_TYPE_UNDEF

-

OUTPUT:

undef method (buildin)
callback: undefined capitalize

define method
callback: added     any_method

undef method
callback: undefined any_method

define method
callback: added     any_method

remove method
callback: removed   any_method
----------------------------------------
Bug #5015: method_added" is called in addition to "method_undefined
http://redmine.ruby-lang.org/issues/5015

Author: Lazaridis Ilias
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: 1.9.2


When a method is undefined via "undef_method :any_method", the following methods are called back:

* method_added 
* method_undefined

The expected behaviour is that only "method_undefined" is called (similar to "remove_method").

-

class String

  def self.method_added(id)
    puts "callback: added     #{id.id2name}"
  end
  
  def self.method_undefined(id)
    puts "callback: undefined #{id.id2name}"
  end
  
  def self.method_removed(id)  
    puts "callback: removed   #{id.id2name}"
  end
  
end

puts "\nundef method (buildin)"
class String
  undef_method :capitalize
end

puts "\ndefine method"
class String
  def any_method(*args)
    nil
  end
end
    
puts "\nundef method"
class String
  undef_method :any_method
end


puts "\ndefine method"
class String
  def any_method(*args)
    nil
  end
end

puts "\nremove method"
class String
  remove_method :any_method
end



-

OUTPUT:


undef method (buildin)
callback: added     capitalize
callback: undefined capitalize

define method
callback: added     any_method

undef method
callback: added     any_method
callback: undefined any_method

define method
callback: added     any_method

remove method
callback: removed   any_method



-- 
http://redmine.ruby-lang.org