diff --git a/lib/ast/node.rb b/lib/ast/node.rb index 320347b..a943f18 100644 --- a/lib/ast/node.rb +++ b/lib/ast/node.rb @@ -80,7 +80,7 @@ def eql?(other) # By default, each entry in the `properties` hash is assigned to # an instance variable in this instance of Node. A subclass should define # attribute readers for such variables. The values passed in the hash - # are not frozen or whitelisted; such behavior can also be implemented\ + # are not frozen or whitelisted; such behavior can also be implemented # by subclassing Node and overriding this method. # # @return [nil] @@ -104,6 +104,7 @@ def assign_properties(properties) def dup self end + alias :clone :dup # Returns a new instance of Node where non-nil arguments replace the # corresponding fields of `self`. diff --git a/test/test_ast.rb b/test/test_ast.rb index cf4619e..76b6a28 100644 --- a/test/test_ast.rb +++ b/test/test_ast.rb @@ -30,6 +30,10 @@ class MetaNode < AST::Node @node.dup.should.equal? @node end + it 'should return self when cloning' do + @node.clone.should.equal? @node + end + it 'should return an updated node, but only if needed' do @node.updated().should.be.identical_to @node @node.updated(:node).should.be.identical_to @node