Module: Holistic::Ruby::Scope::ListInstanceMethods

Extended by:
ListInstanceMethods
Included in:
ListInstanceMethods
Defined in:
lib/holistic/ruby/scope/list_instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#call(scope:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/holistic/ruby/scope/list_instance_methods.rb', line 6

def call(scope:)
  instance_methods = scope.lexical_children.filter(&:instance_method?)
  instance_method_names = ::Set.new(instance_methods.map(&:name))

  ancestor_methods = scope.ancestors.flat_map do |ancestor|
    ancestor_methods = call(scope: ancestor)

    # reject parent methods that were overriden by the subclass
    ancestor_methods.reject { |method| instance_method_names.include?(method.name) }
  end

  instance_methods + ancestor_methods
end