Class: ImproveYourCode::AST::ObjectRefs
- Inherits:
-
Object
- Object
- ImproveYourCode::AST::ObjectRefs
- Defined in:
- lib/improve_your_code/ast/object_refs.rb
Instance Method Summary collapse
-
#initialize ⇒ ObjectRefs
constructor
A new instance of ObjectRefs.
- #most_popular ⇒ Object
- #record_reference(name:, line: nil) ⇒ Object
- #references_to(name) ⇒ Object
- #self_is_max? ⇒ Boolean
Constructor Details
#initialize ⇒ ObjectRefs
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
#most_popular ⇒ Object
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
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 |