Class: Yoga::Node
Overview
A parser node. This can be subclassed, or used as is.
Instance Attribute Summary collapse
-
#location ⇒ Yoga::Location
readonly
The location of the node.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns whether or not the other object is equal to this one.
-
#initialize(attributes) ⇒ Node
constructor
Initialize the node with the given attributes.
-
#prevent_update ⇒ Yoga::Node
Prevents all calls to #update.
-
#update(attributes) ⇒ Object
Creates a new node with the updated attributes.
Constructor Details
#initialize(attributes) ⇒ Node
Initialize the node with the given attributes. The :kind
and
:location
attributes are required.
24 25 26 27 |
# File 'lib/yoga/node.rb', line 24 def initialize(attributes) self.attributes = attributes freeze end |
Instance Attribute Details
#location ⇒ Yoga::Location (readonly)
The location of the node. This is normally dependant on the locations of the tokens that make up this node.
16 |
# File 'lib/yoga/node.rb', line 16 attribute :location, type: Yoga::Location |
Instance Method Details
#==(other) ⇒ Boolean
Returns whether or not the other object is equal to this one. If the other object is this opbject, it returns true; otherwise, if the other object is an instance of this object's class, and the attributes are equal, it returns true; otherwise, it returns false.
46 47 48 49 |
# File 'lib/yoga/node.rb', line 46 def ==(other) equal?(other) || (other.is_a?(self.class) && \ attributes == other.attributes) end |
#prevent_update ⇒ Yoga::Node
57 58 59 60 61 |
# File 'lib/yoga/node.rb', line 57 def prevent_update node = dup node.singleton_class.send(:undef_method, :update) node end |
#update(attributes) ⇒ Object
Creates a new node with the updated attributes. If any unknown attributes are used, it fails.
34 35 36 |
# File 'lib/yoga/node.rb', line 34 def update(attributes) self.class.new(self.attributes.merge(attributes)) end |