lib/sycamore/tree.rb in sycamore-0.2.0 vs lib/sycamore/tree.rb in sycamore-0.2.1

- old
+ new

@@ -324,22 +324,22 @@ self end private def delete_tree(tree) - tree.each do |node, child| + tree.each { |node, child| # using a {} block to circumvent this Rubinius issue: https://github.com/rubinius/rubinius-code/issues/7 raise InvalidNode, "#{node} is not a valid tree node" if node.is_a? Enumerable next unless include? node if Nothing.like?(child) or (child.respond_to?(:empty?) and child.empty?) delete_node node else child_of(node).tap do |this_child| this_child.delete child delete_node(node) if this_child.empty? end end - end + } self end ## @@ -378,13 +378,17 @@ # reference a deeper node with a path of nodes. # # Note that even if you assign a {Sycamore::Tree} directly the given tree # will not become part of this tree by reference. # - # An exception is the assignment of the {Nothing} tree: it will delete the - # child tree at the given path entirely. + # An exception is the assignment of +nil+ or the {Nothing} tree: it will + # delete the child tree at the given path entirely. If you really want to + # overwrite the current child nodes with a single +nil+ node, you'll have to + # assign an array containing only +nil+. # + # tree[:foo] = [nil] + # # @overload []=(*path, node) # Replaces the contents of the child at the given path with a single node. # @param path [Array<Object>, Sycamore::Path] a path as a sequence of nodes or a {Path} object # @param node [Object] # @@ -420,10 +424,10 @@ # def []=(*args) path, nodes_or_tree = args[0..-2], args[-1] raise ArgumentError, 'wrong number of arguments (given 1, expected 2)' if path.empty? - if nodes_or_tree.equal? Sycamore::Nothing + if Nothing.like? nodes_or_tree if path.size == 1 clear_child_of_node(path.first) else path, node = path[0..-2], path[-1] child_at(*path).clear_child_of_node(node)