Class | REXML::Child |
In: |
lib/rexml/child.rb
|
Parent: | Object |
A Child object is something contained by a parent, and this class contains methods to support that. Most user code will not use this class directly.
next_sibling_node | -> | next_sibling |
previous_sibling_node | -> | previous_sibling |
parent | [R] |
Constructor. Any inheritors of this class should call super to make sure this method is called.
parent: | if supplied, the parent of this child will be set to the supplied value, and self will be added to the parent |
# File lib/rexml/child.rb, line 17 17: def initialize( parent = nil ) 18: @parent = nil 19: # Declare @parent, but don't define it. The next line sets the 20: # parent. 21: parent.add( self ) if parent 22: end
This doesn‘t yet handle encodings
# File lib/rexml/child.rb, line 90 90: def bytes 91: encoding = document.encoding 92: 93: to_s 94: end
Sets the next sibling of this child. This can be used to insert a child after some other child.
a = Element.new("a") b = a.add_element("b") c = Element.new("c") b.next_sibling = c # => <a><b/><c/></a>
# File lib/rexml/child.rb, line 67 67: def next_sibling=( other ) 68: parent.insert_after self, other 69: end
Sets the parent of this child to the supplied argument.
other: | Must be a Parent object. If this object is the same object as the existing parent of this child, no action is taken. Otherwise, this child is removed from the current parent (if one exists), and is added to the new parent. |
Returns: | The parent added |
# File lib/rexml/child.rb, line 51 51: def parent=( other ) 52: return @parent if @parent == other 53: @parent.delete self if defined? @parent and @parent 54: @parent = other 55: end
Sets the previous sibling of this child. This can be used to insert a child before some other child.
a = Element.new("a") b = a.add_element("b") c = Element.new("c") b.previous_sibling = c # => <a><b/><c/></a>
# File lib/rexml/child.rb, line 78 78: def previous_sibling=(other) 79: parent.insert_before self, other 80: end
Removes this child from the parent.
Returns: | self |
# File lib/rexml/child.rb, line 36 36: def remove 37: unless @parent.nil? 38: @parent.delete self 39: end 40: self 41: end
Replaces this object with another object. Basically, calls Parent.replace_child
Returns: | self |
# File lib/rexml/child.rb, line 28 28: def replace_with( child ) 29: @parent.replace_child( self, child ) 30: self 31: end