https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-07-11T01:53:13ZRuby Issue Tracking SystemRuby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190532011-07-11T01:53:13Zjudofyr (Magnus Holm)judofyr@gmail.com
<ul></ul><p>But undef_method <em>does</em> actually add a new method: it adds a method<br>
which prevents the superclass' method being called:</p>
<p>class Foo < String; def +() end; undef_method :+ end<br>
Foo.new + "test" # => raises error</p>
<p>class Bar < String; def +() end; remove_method :+ end<br>
Bar.new + "test" # => calls String#+</p>
<p>Seems consistant to me.</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190852011-07-12T01:54:06Zlazaridis.com (Lazaridis Ilias)ilias@lazaridis.com
<ul></ul><p>Magnus Holm wrote:</p>
<blockquote>
<p>But undef_method <em>does</em> actually add a new method: it adds a method<br>
which prevents the superclass' method being called<br>
[...]</p>
</blockquote>
<p>Whatever "undef_method" does, is an internal implementation detail, which should <em>not</em> call "method_added".</p>
<p>undef method<br>
callback: added any_method # false callback, "any_method" was <em>not</em> added by user<br>
callback: undefined any_method # correct callback, "any_method" was undefined by user</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190862011-07-12T02:28:34Zwishdev (John Higgins)wishdev@gmail.com
<ul></ul><p>Lazaridis Ilias wrote:</p>
<blockquote>
<p>Magnus Holm wrote:</p>
<blockquote>
<p>But undef_method <em>does</em> actually add a new method: it adds a method<br>
which prevents the superclass' method being called<br>
[...]</p>
</blockquote>
<p>Whatever "undef_method" does, is an internal implementation detail, which should <em>not</em> call "method_added".</p>
</blockquote>
<p>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.</p>
<blockquote>
<p>undef method<br>
callback: added any_method # false callback, "any_method" was <em>not</em> added by user</p>
</blockquote>
<p>Where exactly is the rule that a method needs to be added by a user to having a callback fired?</p>
<p>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 <em>the user</em> didn't create the strings? Where does one draw the line?</p>
<p>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</p>
<p>class Parent<br>
def hello<br>
puts "In parent"<br>
end<br>
end<br>
class Child < Parent<br>
end</p>
<p>c = Child.new<br>
c.hello</p>
<p>class Child<br>
undef_method :hello # prevent any calls to 'hello'<br>
end</p>
<p>c.hello</p>
<p>Outputs:<br>
In Parent<br>
prog.rb:23: undefined method `hello' for #<a href="Child:0x401b3bb4" class="external">Child:0x401b3bb4</a> (NoMethodError)</p>
<p>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.</p>
<p>Folks again have taken a reasonable step to ensure that both speed and flexibility are met.</p>
<p>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).</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190872011-07-12T03:16:01Zlazaridis.com (Lazaridis Ilias)ilias@lazaridis.com
<ul></ul><p>John Higgins wrote:<br>
[...]</p>
<p>Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:</p>
<ul>
<li>callback: added any_method # false callback, "any_method" was <em>not</em> added by user</li>
</ul>
<p>I'll await the response of the related developer.</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190882011-07-12T03:38:16Zwishdev (John Higgins)wishdev@gmail.com
<ul></ul><p>Lazaridis Ilias wrote:</p>
<blockquote>
<p>John Higgins wrote:<br>
[...]</p>
<p>Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:</p>
<ul>
<li>callback: added any_method # false callback, "any_method" was <em>not</em> added by user</li>
</ul>
</blockquote>
<p>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?</p>
<p>You are nothing if not consistent at least........</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190892011-07-12T04:05:52Zlazaridis.com (Lazaridis Ilias)ilias@lazaridis.com
<ul></ul><p>John Higgins wrote:</p>
<blockquote>
<p>Lazaridis Ilias wrote:</p>
<blockquote>
<p>John Higgins wrote:<br>
[...]</p>
<p>Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:</p>
<ul>
<li>callback: added any_method # false callback, "any_method" was <em>not</em> added by user</li>
</ul>
</blockquote>
<p>Would you care to, even in passing, explain how I'm incorrect when it comes to the Child class example I gave?<br>
[...]</p>
</blockquote>
<p>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.</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190902011-07-12T04:15:00Zlazaridis.com (Lazaridis Ilias)ilias@lazaridis.com
<ul><li><strong>File</strong> <i>method_added_callback.diff</i> added</li></ul><p>[edit: please ignore the first patch send (32kB), the 1001 Bytes one is the correct]</p>
<p>Attached a simple patch, which avoids the method_added callback for</p>
<p>VM_METHOD_TYPE_UNDEF</p>
<ul>
<li>
</ul>
<p>OUTPUT:</p>
<p>undef method (buildin)<br>
callback: undefined capitalize</p>
<p>define method<br>
callback: added any_method</p>
<p>undef method<br>
callback: undefined any_method</p>
<p>define method<br>
callback: added any_method</p>
<p>remove method<br>
callback: removed any_method</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190912011-07-12T04:18:29Zlazaridis.com (Lazaridis Ilias)ilias@lazaridis.com
<ul><li><strong>File</strong> <a href="/attachments/1883">method_added_callback.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/1883/method_added_callback.diff">method_added_callback.diff</a> added</li></ul> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190922011-07-12T04:24:27Zsteveklabnik (Steve Klabnik)steve@steveklabnik.com
<ul></ul><p>+1 on 'not a defect.'</p>
<p>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.</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190932011-07-12T04:26:57Zwishdev (John Higgins)wishdev@gmail.com
<ul></ul><p>Lazaridis Ilias wrote:</p>
<blockquote>
<p>John Higgins wrote:</p>
<blockquote>
<p>Lazaridis Ilias wrote:</p>
<blockquote>
<p>John Higgins wrote:<br>
[...]</p>
<p>Mr. Higgins, you could write a book in your non-technical tenor about this issue, the fact remains:</p>
<ul>
<li>callback: added any_method # false callback, "any_method" was <em>not</em> added by user</li>
</ul>
</blockquote>
<p>Would you care to, even in passing, explain how I'm incorrect when it comes to the Child class example I gave?<br>
[...]</p>
</blockquote>
<p>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.</p>
</blockquote>
<p>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?</p>
<p>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?</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190942011-07-12T04:42:54Zlazaridis.com (Lazaridis Ilias)ilias@lazaridis.com
<ul></ul><p>John Higgins wrote:<br>
[...]</p>
<p>no comment.</p>
<p>"I'll await the response of the related developer."</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190952011-07-12T04:47:57Zwishdev (John Higgins)wishdev@gmail.com
<ul></ul><p>Lazaridis Ilias wrote:</p>
<blockquote>
<p>John Higgins wrote:<br>
[...]</p>
<p>no comment.</p>
<p>"I'll await the response of the related developer."</p>
</blockquote>
<p>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.......</p>
<p>Thanks again!</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190962011-07-12T05:02:14Zantares (Michael Klishin)
<ul></ul><p>Lazaridis Ilias: changing behaviors of the fundamental classes because of one use case doesn't feel right. In fact, it sounds scary.</p> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=190982011-07-12T07:59:00Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>File</strong> deleted (<del><i>method_added_callback.diff</i></del>)</li></ul> Ruby master - Bug #5015: method_added" is called in addition to "method_undefinedhttps://redmine.ruby-lang.org/issues/5015?journal_id=191042011-07-12T17:15:48Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r32527.<br>
Lazaridis, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>vm_method.c (rb_add_method): should not call method_added hook<br>
for undef operation. [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: method_added" is called in addition to "method_undefined (Closed)" href="https://redmine.ruby-lang.org/issues/5015">#5015</a>]</li>
</ul>