Class: TPPlus::Nodes::VarNode

Inherits:
BaseNode
  • Object
show all
Defined in:
lib/tp_plus/nodes/var_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseNode

#can_be_inlined?

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

#identifierObject (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

Returns:

  • (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,options={})
  return target_node(context).eval(context) if constant?

  s = ""
  if options[:opposite]
    s += "!"
  end

  with_parens(s + target_node(context).eval(context, options), options)
end

#requires_mixed_logic?(context) ⇒ Boolean

Returns:

  • (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, options)
  return s unless options[:as_condition]

  "(#{s})"
end