Class: JSE::Ast::ArrayNode
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Attributes inherited from AstNode
Instance Method Summary collapse
- #apply(call_env) ⇒ Object
-
#initialize(elements, env) ⇒ ArrayNode
constructor
A new instance of ArrayNode.
- #to_json ⇒ Object
Constructor Details
#initialize(elements, env) ⇒ ArrayNode
Returns a new instance of ArrayNode.
40 41 42 43 |
# File 'lib/jse/ast/nodes.rb', line 40 def initialize(elements, env) super(env) @elements = elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
45 46 47 |
# File 'lib/jse/ast/nodes.rb', line 45 def elements @elements end |
Instance Method Details
#apply(call_env) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jse/ast/nodes.rb', line 47 def apply(call_env) return [] if @elements.empty? first = @elements.first if first.is_a?(SymbolNode) && JSE::Parser.symbol?(first.name) apply_function_call(call_env, first.name) else @elements.map { |e| call_env.eval(e) } end end |
#to_json ⇒ Object
58 59 60 |
# File 'lib/jse/ast/nodes.rb', line 58 def to_json @elements.map(&:to_json) end |