Class: Reek::CodeContext

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

Overview

Superclass for all types of source code context. Each instance represents a code element of some kind, and each provides behaviour relevant to that code element. CodeContexts form a tree in the same way the code does, with each context holding a reference to a unique outer context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outer, exp) ⇒ CodeContext

Returns a new instance of CodeContext.



20
21
22
23
24
# File 'lib/reek/code_context.rb', line 20

def initialize(outer, exp)
  @outer = outer
  @exp = exp
  @myself = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Bounces messages up the context tree to the first enclosing context that knows how to deal with the request.



39
40
41
# File 'lib/reek/code_context.rb', line 39

def method_missing(method, *args)
  @outer.send(method, *args)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/reek/code_context.rb', line 18

def name
  @name
end

Instance Method Details

#matches?(strings) ⇒ Boolean

SMELL: Temporary Field – @name isn’t always initialized

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/reek/code_context.rb', line 27

def matches?(strings)
  me = @name.to_s
  strings.any? do |str|
    re = /#{str}/
    re === me or re === self.to_s
  end
end

#num_methodsObject



43
44
45
# File 'lib/reek/code_context.rb', line 43

def num_methods
  0
end

#outer_nameObject



47
48
49
# File 'lib/reek/code_context.rb', line 47

def outer_name
  "#{@name}/"
end

#to_sObject



51
52
53
# File 'lib/reek/code_context.rb', line 51

def to_s
  "#{@outer.outer_name}#{@name}"
end