Class: Yadriggy::HashLiteral
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb
Overview
Hash table.
Instance Attribute Summary collapse
-
#pairs ⇒ Array<Array<ASTnode>>
readonly
Returns the elements in the hash table.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#initialize(sexp) ⇒ HashLiteral
constructor
A new instance of HashLiteral.
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class
Constructor Details
#initialize(sexp) ⇒ HashLiteral
Returns a new instance of HashLiteral.
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
# File 'lib/yadriggy/ast.rb', line 766 def initialize(sexp) if sexp[0] == :hash && sexp[1] list = has_tag?(sexp[1], :assoclist_from_args)[1] else list = sexp[1] end if list.nil? @pairs = [] else @pairs = list.map do |e| has_tag?(e, :assoc_new) [to_node(e[1]), to_node(e[2])] end end @pairs.map do |p| add_child(p[0]) add_child(p[1]) end end |
Instance Attribute Details
#pairs ⇒ Array<Array<ASTnode>> (readonly)
Returns the elements in the hash table.
762 763 764 |
# File 'lib/yadriggy/ast.rb', line 762 def pairs @pairs end |
Class Method Details
.tags ⇒ Object
764 |
# File 'lib/yadriggy/ast.rb', line 764 def self.() [:hash, :bare_assoc_hash] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
789 790 791 |
# File 'lib/yadriggy/ast.rb', line 789 def accept(evaluator) evaluator.hash(self) end |