Module: Manipulate
- Included in:
- Rind::Cdata, Rind::Comment, Rind::Element, Rind::ProcessingInstruction, Rind::Text
- Defined in:
- lib/rind/manipulate.rb
Overview
Note: These functions are not available for the root node in a tree.
Instance Method Summary collapse
-
#insert_after(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes after
self. -
#insert_before(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes before
self. -
#remove ⇒ Object
Calls Rind::Children::delete on
self.
Instance Method Details
#insert_after(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes after self.
Example
nodes = ['a', 'b', 'c']
nodes[0].insert_after('d', 'e') => ['a', 'd', 'e', 'b', 'c']
8 9 10 11 |
# File 'lib/rind/manipulate.rb', line 8 def insert_after(*nodes) children = self.parent.children children.insert(children.index(self)+1, *nodes) end |
#insert_before(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes before self.
Example
nodes = ['a', 'b', 'c']
nodes[2].insert_after('d', 'e') => ['a', 'b', 'd', 'e', 'c']
18 19 20 21 |
# File 'lib/rind/manipulate.rb', line 18 def insert_before(*nodes) children = self.parent.children children.insert(children.index(self), *nodes) end |
#remove ⇒ Object
28 29 30 |
# File 'lib/rind/manipulate.rb', line 28 def remove self.parent.children.delete(self) end |