Method: Oga::XML::Node#replace

Defined in:
lib/oga/xml/node.rb

#replace(other) ⇒ Object

Replaces the current node with another.

Examples:

Replacing with an element

element = Oga::XML::Element.new(:name => 'div')
some_node.replace(element)

Replacing with a String

some_node.replace('this will replace the current node with a text node')

Parameters:



131
132
133
134
135
136
137
138
# File 'lib/oga/xml/node.rb', line 131

def replace(other)
  if other.is_a?(String)
    other = Text.new(:text => other)
  end

  before(other)
  remove
end