Project

General

Profile

Actions

Feature #7836

closed

Need a way to get Method and UnboundMethod objects to methods overridden by prepended modules

Added by banister (john mair) almost 12 years ago. Updated about 7 years ago.

Status:
Closed
Target version:
[ruby-core:52160]

Description

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

Files


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #7842: An alias of a "prepend"ed method skips the original method when calling superClosednobu (Nobuyoshi Nakada)02/13/2013Actions
Related to Ruby master - Feature #9781: Feature Proposal: Method#super_methodClosedokkez (okkez _)04/28/2014Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0