Module: Holistic::Ruby::Scope::ListClassMethods

Extended by:
ListClassMethods
Included in:
ListClassMethods
Defined in:
lib/holistic/ruby/scope/list_class_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_class_methods.rb', line 6

def call(scope:)
  class_methods = scope.lexical_children.filter(&:class_method?)
  class_method_names = ::Set.new(class_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| class_method_names.include?(method.name) }
  end

  class_methods + ancestor_methods
end