ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined
@ 2011-07-10 16:11 Lazaridis Ilias
  2011-07-10 16:31 ` [ruby-core:37969] " Magnus Holm
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-10 16:11 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been reported by Lazaridis Ilias.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:37969] Re: [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
@ 2011-07-10 16:31 ` Magnus Holm
  2011-07-11 16:54 ` [ruby-core:37998] [Ruby 1.9 - Bug #5015] " Lazaridis Ilias
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Magnus Holm @ 2011-07-10 16:31 UTC (permalink / raw
  To: ruby-core

But undef_method *does* actually add a new method: it adds a method
which prevents the superclass' method being called:

  class Foo < String; def +() end; undef_method :+ end
  Foo.new + "test" # => raises error

  class Bar < String; def +() end; remove_method :+ end
  Bar.new + "test" # => calls String#+

Seems consistant to me.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:37998] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
  2011-07-10 16:31 ` [ruby-core:37969] " Magnus Holm
@ 2011-07-11 16:54 ` Lazaridis Ilias
  2011-07-11 17:28 ` [ruby-core:37999] " John Higgins
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-11 16:54 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Lazaridis Ilias.


Magnus Holm wrote:
> But undef_method *does* actually add a new method: it adds a method
 which prevents the superclass' method being called
[...]

Whatever "undef_method" does, is an internal implementation detail, which should *not* call "method_added".

undef method
callback: added     any_method # false callback, "any_method" was *not* added by user
callback: undefined any_method # correct callback, "any_method" was undefined by user

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:37999] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
  2011-07-10 16:31 ` [ruby-core:37969] " Magnus Holm
  2011-07-11 16:54 ` [ruby-core:37998] [Ruby 1.9 - Bug #5015] " Lazaridis Ilias
@ 2011-07-11 17:28 ` John Higgins
  2011-07-11 18:16 ` [ruby-core:38000] " Lazaridis Ilias
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: John Higgins @ 2011-07-11 17:28 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by John Higgins.


Lazaridis Ilias wrote:
> Magnus Holm wrote:
> > But undef_method *does* actually add a new method: it adds a method
>  which prevents the superclass' method being called
> [...]
> 
> Whatever "undef_method" does, is an internal implementation detail, which should *not* call "method_added".

What rule exactly says that internal implementations can't fire callbacks? You are specifically interested in internal implementation issues when you are interested in things like "method_added" - there is always a price to peeking under the hood. 

> 
> undef method
> callback: added     any_method # false callback, "any_method" was *not* added by user

Where exactly is the rule that a method needs to be added by a user to having a callback fired? 

Using your vaunted "I want every literal String to fire initialize" concept - when a user "requires" a file at least 10-15 strings are created in the background for a variety of reasons - is your argument that the initialize method shouldn't fire for those because *the user* didn't create the strings? Where does one draw the line?

The undef_method call performs a specific task which you have made an assumption as to why it would be done. Lets assume we look at a variation of the example in the docs

   class Parent
     def hello
       puts "In parent"
     end
   end
   class Child < Parent
   end

   c = Child.new
   c.hello

   class Child
     undef_method :hello   # prevent any calls to 'hello'
   end

   c.hello

Outputs:
In Parent
prog.rb:23: undefined method `hello' for #<Child:0x401b3bb4> (NoMethodError)

In this case I am most certainly adding a method to my Child class because I'm specifically stopping a call from going up to Parent when #hello is called. Whether I use a convenience method like undef_method or write something to throw the method myself - I need to insert something into the call chain to prevent #hello from firing on the Parent class. You've made the assumption, incorrectly, that this can only be used on methods that have been added to a class previous to a undef_method call - that's simply not the case at all.

Folks again have taken a reasonable step to ensure that both speed and flexibility are met.

You are at no disadvantage in terms of understanding what is occurring either because the callbacks fire in a deterministic order for you. You know that if you have a "undefined" callback fire that there is a "added" callback that has just fired - you can easily revert any tracking that the added callback did for you if you wanted to (except if you want to know which methods actual exist on a class because undef_method certainly can add a method to a class).
----------------------------------------
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38000] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (2 preceding siblings ...)
  2011-07-11 17:28 ` [ruby-core:37999] " John Higgins
@ 2011-07-11 18:16 ` Lazaridis Ilias
  2011-07-11 18:38 ` [ruby-core:38002] " John Higgins
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-11 18:16 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Lazaridis Ilias.


John Higgins wrote:
[...]

Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:

* callback: added     any_method # false callback, "any_method" was *not* added by user

I'll await the response of the related developer.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38002] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (3 preceding siblings ...)
  2011-07-11 18:16 ` [ruby-core:38000] " Lazaridis Ilias
@ 2011-07-11 18:38 ` John Higgins
  2011-07-11 19:05 ` [ruby-core:38003] " Lazaridis Ilias
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: John Higgins @ 2011-07-11 18:38 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by John Higgins.


Lazaridis Ilias wrote:
> John Higgins wrote:
> [...]
> 
> Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:
> 
> * callback: added     any_method # false callback, "any_method" was *not* added by user

Would you care to, even in passing, explain how I'm incorrect when it comes to the Child class example I gave? Or does clear, simple, 13 line examples showing specific cases where your hypothesis is incorrect too "non-technical a tenor" for you?

You are nothing if not consistent at least........
----------------------------------------
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38003] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (4 preceding siblings ...)
  2011-07-11 18:38 ` [ruby-core:38002] " John Higgins
@ 2011-07-11 19:05 ` Lazaridis Ilias
  2011-07-11 19:15 ` [ruby-core:38004] " Lazaridis Ilias
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-11 19:05 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Lazaridis Ilias.


John Higgins wrote:
> Lazaridis Ilias wrote:
> > John Higgins wrote:
> > [...]
> > 
> > Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:
> > 
> > * callback: added     any_method # false callback, "any_method" was *not* added by user
> 
> Would you care to, even in passing, explain how I'm incorrect when it comes to the Child class example I gave? 
[...]

No, I can't, because it is irrelevant (and thus I do not invest any energy to analyse). I've provided a use-case. In context of this use-case, the callback "method_added :capitalize" is false, and thus a defect. There's really no need to change context or use-cases: the defect in this use-case remains.
----------------------------------------
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38004] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (5 preceding siblings ...)
  2011-07-11 19:05 ` [ruby-core:38003] " Lazaridis Ilias
@ 2011-07-11 19:15 ` Lazaridis Ilias
  2011-07-11 19:18 ` [ruby-core:38005] " Lazaridis Ilias
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-11 19:15 UTC (permalink / raw
  To: ruby-core


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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38005] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (6 preceding siblings ...)
  2011-07-11 19:15 ` [ruby-core:38004] " Lazaridis Ilias
@ 2011-07-11 19:18 ` Lazaridis Ilias
  2011-07-11 19:24 ` [ruby-core:38006] " Steve Klabnik
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-11 19:18 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Lazaridis Ilias.

File method_added_callback.diff added


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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38006] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (7 preceding siblings ...)
  2011-07-11 19:18 ` [ruby-core:38005] " Lazaridis Ilias
@ 2011-07-11 19:24 ` Steve Klabnik
  2011-07-11 19:26 ` [ruby-core:38007] " John Higgins
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Steve Klabnik @ 2011-07-11 19:24 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Steve Klabnik.


+1 on 'not a defect.'

If a method is added, I expect the method_added callback to be fired. undef_method adds a method. This is pretty open-and-shut.
----------------------------------------
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38007] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (8 preceding siblings ...)
  2011-07-11 19:24 ` [ruby-core:38006] " Steve Klabnik
@ 2011-07-11 19:26 ` John Higgins
  2011-07-11 19:42 ` [ruby-core:38008] " Lazaridis Ilias
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: John Higgins @ 2011-07-11 19:26 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by John Higgins.


Lazaridis Ilias wrote:
> John Higgins wrote:
> > Lazaridis Ilias wrote:
> > > John Higgins wrote:
> > > [...]
> > > 
> > > Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:
> > > 
> > > * callback: added     any_method # false callback, "any_method" was *not* added by user
> > 
> > Would you care to, even in passing, explain how I'm incorrect when it comes to the Child class example I gave? 
> [...]
> 
> No, I can't, because it is irrelevant (and thus I do not invest any energy to analyse). I've provided a use-case. In context of this use-case, the callback "method_added :capitalize" is false, and thus a defect. There's really no need to change context or use-cases: the defect in this use-case remains.

Again, what are you basing this on? I asked you what rule/concept states that internal implementations cannot fire callbacks. Why is it an error if the implementation of undef_method adds a method to the class? Where is the definition of undef_method that states anything about its implementation? In fact the docs state only the following "Prevents the current class from responding to calls to the named method." - why exactly is that at odds with a method_added callback being fired during the execution of an undef_method call?

Would you only call this a bug in a class with a "direct" definition of a method (i.e. non-inherited method). What about the user that wants to track the addition of the "blocking" method to the subclass if you wanted the method_added subclass suppressed even in a subclass without a direct definition of a 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38008] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (9 preceding siblings ...)
  2011-07-11 19:26 ` [ruby-core:38007] " John Higgins
@ 2011-07-11 19:42 ` Lazaridis Ilias
  2011-07-11 19:47 ` [ruby-core:38009] " John Higgins
  2011-07-11 20:02 ` [ruby-core:38010] " Michael Klishin
  12 siblings, 0 replies; 14+ messages in thread
From: Lazaridis Ilias @ 2011-07-11 19:42 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Lazaridis Ilias.


John Higgins wrote:
[...]

no comment.

"I'll await the response of the related developer."



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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38009] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (10 preceding siblings ...)
  2011-07-11 19:42 ` [ruby-core:38008] " Lazaridis Ilias
@ 2011-07-11 19:47 ` John Higgins
  2011-07-11 20:02 ` [ruby-core:38010] " Michael Klishin
  12 siblings, 0 replies; 14+ messages in thread
From: John Higgins @ 2011-07-11 19:47 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by John Higgins.


Lazaridis Ilias wrote:
> John Higgins wrote:
> [...]
> 
> no comment.
> 
> "I'll await the response of the related developer."

Very technical response - thanks for the rebuttal, I'm sure the "related developer" will be more than happy to implement a patch which turns off a callback that clearly and without question is valid in a multitude of cases. Your reasoned argument clearly shows the error of my ways.......

Thanks again!
----------------------------------------
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:38010] [Ruby 1.9 - Bug #5015] method_added" is called in addition to "method_undefined
  2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
                   ` (11 preceding siblings ...)
  2011-07-11 19:47 ` [ruby-core:38009] " John Higgins
@ 2011-07-11 20:02 ` Michael Klishin
  12 siblings, 0 replies; 14+ messages in thread
From: Michael Klishin @ 2011-07-11 20:02 UTC (permalink / raw
  To: ruby-core


Issue #5015 has been updated by Michael Klishin.


Lazaridis Ilias: changing behaviors of the fundamental classes because of one use case doesn't feel right. In fact, it sounds scary.
----------------------------------------
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-07-11 19:50 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-10 16:11 [ruby-core:37968] [Ruby 1.9 - Bug #5015][Open] method_added" is called in addition to "method_undefined Lazaridis Ilias
2011-07-10 16:31 ` [ruby-core:37969] " Magnus Holm
2011-07-11 16:54 ` [ruby-core:37998] [Ruby 1.9 - Bug #5015] " Lazaridis Ilias
2011-07-11 17:28 ` [ruby-core:37999] " John Higgins
2011-07-11 18:16 ` [ruby-core:38000] " Lazaridis Ilias
2011-07-11 18:38 ` [ruby-core:38002] " John Higgins
2011-07-11 19:05 ` [ruby-core:38003] " Lazaridis Ilias
2011-07-11 19:15 ` [ruby-core:38004] " Lazaridis Ilias
2011-07-11 19:18 ` [ruby-core:38005] " Lazaridis Ilias
2011-07-11 19:24 ` [ruby-core:38006] " Steve Klabnik
2011-07-11 19:26 ` [ruby-core:38007] " John Higgins
2011-07-11 19:42 ` [ruby-core:38008] " Lazaridis Ilias
2011-07-11 19:47 ` [ruby-core:38009] " John Higgins
2011-07-11 20:02 ` [ruby-core:38010] " Michael Klishin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).