lib/hexp/node.rb
def rewrite(css_selector = nil, &block)
      return Rewriter.new(self, block) if css_selector.nil?
      CssSelection.new(self, css_selector).rewrite(&block)
    end
def rewrite(css_selector = nil, &block)
      return Rewriter.new(self, block) if css_selector.nil?
      CssSelection.new(self, css_selector).rewrite(&block)
    end
Replace nodes in a tree

 With a CSS selector string like +"form.checkout"+ you specify the nodes
 you want to operate on. These will be passed one by one into the block.
 The block returns the {Hexp::Node} that will replace the old node, or it
 can replace an +Array+ of nodes to fill the place of the old node.

 Because of this you can add one or more nodes, or remove nodes by
 returning an empty array.

 @example Remove all script tags
   tree.replace('script') {|_| [] }

 @example Wrap each +<input>+ tag into a +<p>+ tag
   tree.replace('input') do |input|
     H[:p, input]
   end

 @param [String] css_selector

 @yieldparam [Hexp::Node]
   The matching nodes

 @return [Hexp::Node]
   The rewritten tree

 @api public