Method: AST::Node#initialize

Defined in:
lib/ast/node.rb

#initialize(type, children = [], properties = {}) ⇒ Node

Constructs a new instance of Node.

The arguments ‘type` and `children` are converted with `to_sym` and `to_a` respectively. Additionally, the result of converting `children` is frozen. While mutating the arguments is generally considered harmful, the most common case is to pass an array literal to the constructor. If your code does not expect the argument to be frozen, use `#dup`.

The ‘properties` hash is passed to #assign_properties.



72
73
74
75
76
77
78
79
80
# File 'lib/ast/node.rb', line 72

def initialize(type, children=[], properties={})
  @type, @children = type.to_sym, children.to_a.freeze

  assign_properties(properties)

  @hash = [@type, @children, self.class].hash

  freeze
end