Class: Reek::ObjectRefs

Inherits:
Object show all
Defined in:
lib/reek/object_refs.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeObjectRefs

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_keysObject

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_refsObject



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_selfObject



11
12
13
# File 'lib/reek/object_refs.rb', line 11

def record_reference_to_self
  record_ref(SELF_REF)
end

#refs_to_selfObject



27
28
29
# File 'lib/reek/object_refs.rb', line 27

def refs_to_self
  @refs[SELF_REF]
end

#self_is_max?Boolean

Returns:

  • (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