Class: Reek::ObjectRefs
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize ⇒ ObjectRefs
constructor
A new instance of ObjectRefs.
-
#max_keys ⇒ Object
TODO Should be moved to Hash.
- #max_refs ⇒ Object
- #record_ref(exp) ⇒ Object
- #record_reference_to_self ⇒ Object
- #refs_to_self ⇒ Object
- #self_is_max? ⇒ Boolean
Constructor Details
#initialize ⇒ ObjectRefs
Returns a new instance of ObjectRefs.
7 8 9 |
# File 'lib/reek/object_refs.rb', line 7 def initialize @refs = Hash.new(0) end |
Instance Method Details
#max_keys ⇒ Object
TODO Should be moved to Hash
38 39 40 41 |
# File 'lib/reek/object_refs.rb', line 38 def max_keys max = max_refs @refs.reject {|key,val| val != max}.keys end |
#max_refs ⇒ Object
31 32 33 |
# File 'lib/reek/object_refs.rb', line 31 def max_refs @refs.values.max or 0 end |
#record_ref(exp) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/reek/object_refs.rb', line 15 def record_ref(exp) type = exp[0] case type when :gvar return when :self record_reference_to_self else @refs[exp] += 1 end end |
#record_reference_to_self ⇒ Object
11 12 13 |
# File 'lib/reek/object_refs.rb', line 11 def record_reference_to_self record_ref(SELF_REF) end |
#refs_to_self ⇒ Object
27 28 29 |
# File 'lib/reek/object_refs.rb', line 27 def refs_to_self @refs[SELF_REF] end |
#self_is_max? ⇒ Boolean
43 44 45 |
# File 'lib/reek/object_refs.rb', line 43 def self_is_max? max_keys.length == 0 || @refs[SELF_REF] == max_refs end |