mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
WrappedModule now ignores def_delegator methods, fixes #801
If a class had most of its methods defined by def_delegators, the module extraction code would break. This was due to Pry::WrappedModule looking for the class definition in fowardable.rb. We now just simply reject all methods that have source_location.first =~ /forwardable\.rb/
This commit is contained in:
parent
44710d952e
commit
de9a839dc4
1 changed files with 10 additions and 1 deletions
|
@ -273,7 +273,7 @@ class Pry
|
|||
# @return [Array<Pry::Method>]
|
||||
def all_relevant_methods_for(mod)
|
||||
all_methods_for(mod).select(&:source_location).
|
||||
reject{ |x| x.name == '__class_init__' }
|
||||
reject{ |x| x.name == '__class_init__' || method_defined_by_forwardable_module?(x) }
|
||||
end
|
||||
|
||||
# Return all methods (instance methods and class methods) for a
|
||||
|
@ -298,6 +298,15 @@ class Pry
|
|||
end.flatten
|
||||
end
|
||||
|
||||
# Detect methods that are defined with `def_delegator` from the Forwardable
|
||||
# module. We want to reject these methods as they screw up module
|
||||
# extraction since the `source_location` for such methods points at forwardable.rb
|
||||
# TODO: make this more robust as valid user-defined files called
|
||||
# forwardable.rb are also skipped.
|
||||
def method_defined_by_forwardable_module?(method)
|
||||
method.source_location.first =~ /forwardable\.rb/
|
||||
end
|
||||
|
||||
# memoized lines for file
|
||||
def lines_for_file(file)
|
||||
@lines_for_file ||= {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue