# File htree/doc.rb, line 47 def subst_subnode(hash) hash.each_pair {|index, value| unless Integer === index raise TypeError, "invalid index: #{index.inspect}" end } children_left = [] children = @children.dup children_right = [] hash.each_pair {|index, value| if index < 0 children_left << value elsif children.length <= index children_right << value else children[index] = value end } children = [children_left, children, children_right].flatten.compact Doc.new(children) end