Class: ImproveYourCode::AST::ObjectRefs

Inherits:
Object
  • Object
show all
Defined in:
lib/improve_your_code/ast/object_refs.rb

Instance Method Summary collapse

Constructor Details

#initializeObjectRefs

Returns a new instance of ObjectRefs.



6
7
8
# File 'lib/improve_your_code/ast/object_refs.rb', line 6

def initialize
  @refs = Hash.new { |refs, name| refs[name] = [] }
end

Instance Method Details



14
15
16
17
# File 'lib/improve_your_code/ast/object_refs.rb', line 14

def most_popular
  max = refs.values.map(&:size).max
  refs.select { |_name, refs| refs.size == max }
end

#record_reference(name:, line: nil) ⇒ Object



10
11
12
# File 'lib/improve_your_code/ast/object_refs.rb', line 10

def record_reference(name:, line: nil)
  refs[name] << line
end

#references_to(name) ⇒ Object



19
20
21
# File 'lib/improve_your_code/ast/object_refs.rb', line 19

def references_to(name)
  refs[name]
end

#self_is_max?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/improve_your_code/ast/object_refs.rb', line 23

def self_is_max?
  refs.empty? || most_popular.keys.include?(:self)
end