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

- old
+ new

@@ -133,6 +133,30 @@ # @return [Node] Returns the root node def root ascend(parent) {|e| return e unless e.parent } end + # Converts self to a hash + # @return [Hash] the converted hash + # @since 0.3.0 + def to_hash + {}.merge(self) + end + + # @return [String] a textual representation of self + # @since 0.3.0 + def inspect + string = "" + descend do |e, level| + string << " "*level+e.to_hash.inspect+"\n" + end + string.chomp + end + + # @return (Boolean) true if the nodes are equal + # @since 0.3.0 + def ==(node) + return false unless node.is_a? Node + self.to_hash == node.to_hash && self.children == node.children + end + end