Class: Reek::CodeContext
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.
Direct Known Subclasses
BlockContext, ClassContext, IfContext, MethodContext, ModuleContext, YieldCallContext
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(outer, exp) ⇒ CodeContext
constructor
A new instance of CodeContext.
-
#matches?(strings) ⇒ Boolean
SMELL: Temporary Field – @name isn’t always initialized.
-
#method_missing(method, *args) ⇒ Object
Bounces messages up the context tree to the first enclosing context that knows how to deal with the request.
- #num_methods ⇒ Object
- #outer_name ⇒ Object
- #to_s ⇒ Object
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
#name ⇒ Object (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
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_methods ⇒ Object
43 44 45 |
# File 'lib/reek/code_context.rb', line 43 def num_methods 0 end |
#outer_name ⇒ Object
47 48 49 |
# File 'lib/reek/code_context.rb', line 47 def outer_name "#{@name}/" end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/reek/code_context.rb', line 51 def to_s "#{@outer.outer_name}#{@name}" end |