Class: Yadriggy::ArrayLiteral
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Array literal.
Instance Attribute Summary collapse
-
#elements ⇒ Array<ASTnode>
readonly
The array elements.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
- #const_value ⇒ Object
-
#initialize(sexp) ⇒ ArrayLiteral
constructor
A new instance of ArrayLiteral.
- #value ⇒ Object
- #value_in_class(klass) ⇒ Object
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string
Constructor Details
#initialize(sexp) ⇒ ArrayLiteral
Returns a new instance of ArrayLiteral.
436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/yadriggy/ast.rb', line 436 def initialize(sexp) if sexp[1].nil? @elements = [] elsif is_percent_literal(sexp[1]) @elements = sexp[1].map do |e| StringInterpolation.new([:string_literal, [:string_content] + e]) end else @elements = to_nodes(sexp[1]) end add_children(@elements) end |
Instance Attribute Details
#elements ⇒ Array<ASTnode> (readonly)
Returns the array elements.
432 433 434 |
# File 'lib/yadriggy/ast.rb', line 432 def elements @elements end |
Class Method Details
.tag ⇒ Object
434 |
# File 'lib/yadriggy/ast.rb', line 434 def self.tag() :array end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
452 453 454 |
# File 'lib/yadriggy/ast.rb', line 452 def accept(evaluator) evaluator.array(self) end |
#const_value ⇒ Object
279 280 281 |
# File 'lib/yadriggy/ast_value.rb', line 279 def const_value() elements.map {|e| e.const_value } end |
#value ⇒ Object
271 272 273 |
# File 'lib/yadriggy/ast_value.rb', line 271 def value() elements.map {|e| e.value } end |
#value_in_class(klass) ⇒ Object
275 276 277 |
# File 'lib/yadriggy/ast_value.rb', line 275 def value_in_class(klass) elements.map {|e| e.value_in_class(klass) } end |