lib/glyph/node.rb in glyph-0.1.0 vs lib/glyph/node.rb in glyph-0.2.0

- old
+ new

@@ -53,17 +53,29 @@ ht = hash.to_node ht.parent = self @children << ht end + # Removes a child node from self + # @param [node] node the child node to remove + # @raise [ArgumentError] unless an existing child node is passed as parameter + def >>(node) + raise ArgumentError, "Unknown child node" unless @children.include? node + node.parent = nil + @children.delete node + end + # Returns a child by its index # @return [Node] the child node or nil # @param [Integer] index the child index def child(index) @children[index] end - alias >> child + # See Node#child. + def &(index) + @children[index] + end # Iterates through children # @yieldparam [Node] c the child node def each_child @children.each {|c| yield c }