Class: MethodSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/xray_method_tracer/methods/method_selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ MethodSelector

Returns a new instance of MethodSelector.



6
7
8
# File 'lib/xray_method_tracer/methods/method_selector.rb', line 6

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/xray_method_tracer/methods/method_selector.rb', line 4

def klass
  @klass
end

Instance Method Details

#select_method_names_by_source_location(source_locations) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xray_method_tracer/methods/method_selector.rb', line 10

def select_method_names_by_source_location(source_locations)
  all_instance_method_names = klass.instance_methods(false)
  return all_instance_method_names if source_locations.empty?

  all_instance_method_names.map do |method_name|
    source_location = klass.instance_method(method_name).source_location.first
    next unless source_location.start_with?(*source_locations)

    method_name
  end.compact
  # NOTE: nextを使ったらnilが配列に入って返ってくるので、compactでnilを除外する
end