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.



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

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

Returns:

  • (Boolean)


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

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

#num_methodsObject



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

def num_methods
  0
end

#outer_nameObject



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

def outer_name
  "#{@name}/"
end

#to_sObject



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

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