Class: TPPlus::Nodes::VarNode
- Defined in:
- lib/tp_plus/nodes/var_node.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #constant? ⇒ Boolean
- #eval(context, options = {}) ⇒ Object
-
#initialize(identifier) ⇒ VarNode
constructor
A new instance of VarNode.
- #requires_mixed_logic?(context) ⇒ Boolean
- #target_node(context) ⇒ Object
- #with_parens(s, options) ⇒ Object
Methods inherited from BaseNode
Constructor Details
#initialize(identifier) ⇒ VarNode
Returns a new instance of VarNode.
5 6 7 |
# File 'lib/tp_plus/nodes/var_node.rb', line 5 def initialize(identifier) @identifier = identifier end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/tp_plus/nodes/var_node.rb', line 4 def identifier @identifier end |
Instance Method Details
#constant? ⇒ Boolean
13 14 15 |
# File 'lib/tp_plus/nodes/var_node.rb', line 13 def constant? @identifier.upcase == @identifier end |
#eval(context, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tp_plus/nodes/var_node.rb', line 27 def eval(context,={}) return target_node(context).eval(context) if constant? s = "" if [:opposite] s += "!" end with_parens(s + target_node(context).eval(context, ), ) end |
#requires_mixed_logic?(context) ⇒ Boolean
17 18 19 |
# File 'lib/tp_plus/nodes/var_node.rb', line 17 def requires_mixed_logic?(context) target_node(context).requires_mixed_logic?(context) end |
#target_node(context) ⇒ Object
9 10 11 |
# File 'lib/tp_plus/nodes/var_node.rb', line 9 def target_node(context) constant? ? context.get_constant(@identifier) : context.get_var(@identifier) end |
#with_parens(s, options) ⇒ Object
21 22 23 24 25 |
# File 'lib/tp_plus/nodes/var_node.rb', line 21 def with_parens(s, ) return s unless [:as_condition] "(#{s})" end |