Fix show_source command when obj.method is overrided#1111
Conversation
lib/irb/source_finder.rb
Outdated
| target_method = owner_receiver.instance_method(method) | ||
| when "receiver" | ||
| target_method = owner_receiver.method(method) | ||
| target_method = Object.instance_method(:method).bind_call(owner_receiver, method) |
There was a problem hiding this comment.
I think we already store the method method in KERNEL_METHOD under Context. Perhaps we can create a module under IRB, like IRB::ORIGINAL_METHODS::KERNEL_METHOD, to host these method objects and reuse them in different places?
There was a problem hiding this comment.
It'd be good to introduce something like IRB::ORIGINAL_METHODS 👍
In context.rb and in completion.rb, method is called in each keystroke. But in SourceFinder, it is only called once per show_source. Needs for storing is not that high here, so I want to pend doing it for now in this pull request.
Anyway, thanks for finding KERNEL_METHOD. I updated Object.instance_method(:method) to Kernel.instance_method(:method) since def method; end in top level overrides Object's method.
There was a problem hiding this comment.
That's fair. Feel free to ship it then!
`method` method is sometimes overridden. (example: Net::HTTPRequest) To handle this case, use `Object.instance_method(:method).bind_call` instead of `obj.method(name)`
d6b51ef to
2785cbe
Compare
methodmethod is sometimes overridden.Fixes this error