| Class | REXML::Parent |
| In: |
rexml/parent.rb
|
| Parent: | Child |
Constructor @param parent if supplied, will be set as the parent of this object
# File rexml/parent.rb, line 12 def initialize parent=nil super(parent) @children = [] end
Set an index entry. See Array.[]= @param index the index of the element to set @param opt either the object to set, or an Integer length @param child if opt is an Integer, this is the child to set @return the parent (self)
# File rexml/parent.rb, line 70 def []=( *args ) args[-1].parent = self @children[*args[0..-2]] = args[-1] end
# File rexml/parent.rb, line 17 def add( object ) #puts "PARENT GOTS #{size} CHILDREN" object.parent = self @children << object #puts "PARENT NOW GOTS #{size} CHILDREN" object end
# File rexml/parent.rb, line 33 def delete( object ) found = false @children.delete_if {|c| c.equal?(object) and found = true } object.parent = nil if found end
Inserts an child after another child @param child1 this is either an xpath or an Element. If an Element, child2 will be inserted after child1 in the child list of the parent. If an xpath, child2 will be inserted after the first child to match the xpath. @param child2 the child to insert @return the parent (self)
# File rexml/parent.rb, line 102 def insert_after( child1, child2 ) if child1.kind_of? String child1 = XPath.first( self, child1 ) child1.parent.insert_after child1, child2 else ind = index(child1)+1 child2.parent.delete(child2) if child2.parent @children[ind,0] = child2 child2.parent = self end self end
Inserts an child before another child @param child1 this is either an xpath or an Element. If an Element, child2 will be inserted before child1 in the child list of the parent. If an xpath, child2 will be inserted before the first child to match the xpath. @param child2 the child to insert @return the parent (self)
# File rexml/parent.rb, line 82 def insert_before( child1, child2 ) if child1.kind_of? String child1 = XPath.first( self, child1 ) child1.parent.insert_before child1, child2 else ind = index(child1) child2.parent.delete(child2) if child2.parent @children[ind,0] = child2 child2.parent = self end self end
Replaces one child with another, making sure the nodelist is correct @param to_replace the child to replace (must be a Child) @param replacement the child to insert into the nodelist (must be a Child)
# File rexml/parent.rb, line 140 def replace_child( to_replace, replacement ) @children.map! {|c| c.equal?( to_replace ) ? replacement : c } to_replace.parent = nil replacement.parent = self end
ruby-doc.org is a community service provided by Happy Camper Studios, a Phoenix, Arizona, Ruby application development company.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.