Class: REXML::Child (Ruby 2.4.2)
Description: Class : REXML::Child - Ruby 2.4.2

Support for the Ruby 2.4 series has ended. See here for reference.

### Home Classes Methods

### In Files

- rexml/child.rb

### Parent

Object

### Methods

- ::new
- #bytes
- #document
- #next_sibling=
- #parent=
- #previous_sibling=
- #remove
- #replace_with

### Included Modules

- REXML::Node

### Class/Module Index

Quicksearch

- Array
- Float
- Integer
- Object
- REXML
- REXML::AttlistDecl
- REXML::Attribute
- REXML::Attributes
- REXML::CData
- REXML::Child
- REXML::Comment
- REXML::DTD
- REXML::DTD::AttlistDecl
- REXML::DTD::ElementDecl
- REXML::DTD::EntityDecl
- REXML::DTD::NotationDecl
- REXML::DTD::Parser
- REXML::Declaration
- REXML::DocType
- REXML::Document
- REXML::Element
- REXML::ElementDecl
- REXML::Elements
- REXML::Encoding
- REXML::Entity
- REXML::EntityConst
- REXML::ExternalEntity
- REXML::Formatters
- REXML::Formatters::Default
- REXML::Formatters::Pretty
- REXML::Formatters::Transitive
- REXML::Functions
- REXML::IOSource
- REXML::Instruction
- REXML::Light
- REXML::Light::Node
- REXML::Namespace
- REXML::Node
- REXML::NotationDecl
- REXML::Output
- REXML::Parent
- REXML::ParseException
- REXML::Parsers
- REXML::Parsers::BaseParser
- REXML::Parsers::LightParser
- REXML::Parsers::PullEvent
- REXML::Parsers::PullParser
- REXML::Parsers::SAX2Parser
- REXML::Parsers::StreamParser
- REXML::Parsers::TreeParser
- REXML::Parsers::UltraLightParser
- REXML::Parsers::XPathParser
- REXML::QuickPath
- REXML::SAX2Listener
- REXML::Security
- REXML::Source
- REXML::SourceFactory
- REXML::StreamListener
- REXML::SyncEnumerator
- REXML::Text
- REXML::UndefinedNamespaceException
- REXML::Validation
- REXML::Validation::Choice
- REXML::Validation::Event
- REXML::Validation::Interleave
- REXML::Validation::OneOrMore
- REXML::Validation::Optional
- REXML::Validation::Ref
- REXML::Validation::RelaxNG
- REXML::Validation::Sequence
- REXML::Validation::State
- REXML::Validation::ValidationException
- REXML::Validation::Validator
- REXML::Validation::ZeroOrMore
- REXML::XMLDecl
- REXML::XMLTokens
- REXML::XPath
- REXML::XPathParser
- Symbol

No matching classes.

# REXML::Child

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.

### Attributes

parent[R]

### Public Class Methods

new( parent = nil ) click to toggle source

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 rexml/child.rb, line 18
    def initialize( parent = nil )
      @parent = nil
      # Declare @parent, but don't define it.  The next line sets the
      # parent.
      parent.add( self ) if parent
    end

### Public Instance Methods

bytes() click to toggle source

This doesn't yet handle encodings

                   # File rexml/child.rb, line 91
    def bytes
      document.encoding

      to_s
    end

document() click to toggle source

Returns

  the document this child belongs to, or nil if this child

belongs to no document

                   # File rexml/child.rb, line 85
    def document
      return parent.document unless parent.nil?
      nil
    end

next_sibling=( other ) click to toggle source

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 rexml/child.rb, line 68
    def next_sibling=( other )
      parent.insert_after self, other
    end

parent=( other ) click to toggle source

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 rexml/child.rb, line 52
    def parent=( other )
      return @parent if @parent == other
      @parent.delete self if defined? @parent and @parent
      @parent = other
    end

previous_sibling=(other) click to toggle source

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 rexml/child.rb, line 79
    def previous_sibling=(other)
      parent.insert_before self, other
    end

remove() click to toggle source

Removes this child from the parent.

Returns

  self

                   # File rexml/child.rb, line 37
    def remove
      unless @parent.nil?
        @parent.delete self
      end
      self
    end

replace_with( child ) click to toggle source

Replaces this object with another object. Basically, calls `Parent.replace_child`

Returns

  self

                   # File rexml/child.rb, line 29
    def replace_with( child )
      @parent.replace_child( self, child )
      self
    end