From: "marcandre (Marc-Andre Lafortune)" Date: 2013-02-15T00:57:48+09:00 Subject: [ruby-core:52260] [ruby-trunk - Bug #7836][Open] Need a way to get Method and UnboundMethod objects to methods overridden by prepended modules Issue #7836 has been updated by marcandre (Marc-Andre Lafortune). Status changed from Closed to Open Assignee set to matz (Yukihiro Matsumoto) Matz, could you please confirm? I'm not sure what is the right approach. What should A.instance_method(:hello) return: 1) the method that `A.new.hello` will execute, or 2) the method defined in A? I feel that 1) is currently the case. Otherwise, strictly speaking, `String.instance_method(:object_id)` would raise a NameError! I would expect: meth = A.instance_method :hello a = A.new meth.bind(a).call `# should be the same effect as a.bar meth.source_location ` # thus should be the same as a.method(:hello).source_location meth.owner ` # and thus should be the same as a.method(:hello).owner This is currently true in Ruby 1.9, and this patch changes that. I agree with John Mair that there should be a way to get the proper instance method of a class, as he suggests. I would add that String.instance_method(:object_id, false) should raise a NameError, as there is no such instance method defined in String. ---------------------------------------- Bug #7836: Need a way to get Method and UnboundMethod objects to methods overridden by prepended modules https://bugs.ruby-lang.org/issues/7836#change-36291 Author: banister (john mair) Status: Open Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: ruby -v: 2.0.0dev =begin See the following code: module P def hello puts "from P" super end end class A def hello puts 'from A' end prepend P end A.instance_method(:hello).source_location == P.instance_method(:hello).source_location #=> true == Discussion Since (({A.instance_method(:hello)})) effectively returns (({P.instance_method(:hello)})) it is impossible to get an (({UnboundMethod})) object to the original (({A#hello})) method. Tools like ((<[Pry]|URL:http://pryrepl.org>)) need to access (({UnboundMethod})) objects to every active method in the system for debugging purposes. == Possible solution Simply allow (({instance_method()})) to take a second boolean parameter, indicating whether methods injected by prepended modules are to be included, it would default to true: example: A.instance_method(:hello) #=> same as P#hello A.instance_method(:hello, false) #=> return strictly A#hello =end -- http://bugs.ruby-lang.org/