123456789_123456789_123456789_123456789_123456789_

Class: REXML::Comment

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Child
Instance Chain:
self, Comparable, Child, Node
Inherits: REXML::Child
Defined in: lib/rexml/comment.rb

Overview

Represents an XML comment; that is, text between <!– … –>

Constant Summary

Class Method Summary

Child - Inherited

.new

Constructor.

Instance Attribute Summary

Child - Inherited

#next_sibling
#next_sibling=

Sets the next sibling of this child.

#parent

The Parent of this object.

#parent=

Sets the parent of this child to the supplied argument.

#previous_sibling
#previous_sibling=

Sets the previous sibling of this child.

Node - Included

Instance Method Summary

Child - Inherited

#bytes

This doesn’t yet handle encodings.

#document
Returns

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

#remove

Removes this child from the parent.

#replace_with

Replaces this object with another object.

Node - Included

#each_recursive

Visit all subnodes of self recursively.

#find_first_recursive

Find (and return) first subnode (recursively) for which the block evaluates to true.

#indent,
#index_in_parent

Returns the position that self holds in its parent’s array, indexed from 1.

#next_sibling_node, #previous_sibling_node,
#to_s
indent

Constructor Details

.new(first, second = nil) ⇒ Comment

Constructor. The first argument can be one of three types: argument. If Comment, the argument is duplicated. If Source, the argument is scanned for a comment. should be nil, not supplied, or a Parent to be set as the parent of this object

Parameters:

  • first

    If String, the contents of this comment are set to the

  • second (defaults to: nil)

    If the first argument is a Source, this argument

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 24

def initialize( first, second = nil )
  super(second)
  if first.kind_of? String
    @string = first
  elsif first.kind_of? Comment
    @string = first.string
  end
end

Instance Attribute Details

#string (rw) Also known as: #to_s

The content text

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 14

attr_accessor :string

#to_s (readonly)

Alias for #string.

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 58

alias :to_s :string

Instance Method Details

#<=>(other)

Compares this Comment to another; the contents of the comment are used in the comparison.

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 63

def <=>(other)
  other.to_s <=> @string
end

#==(other)

Compares this Comment to another; the contents of the comment are used in the comparison.

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 70

def ==( other )
  other.kind_of? Comment and
  (other <=> self) == 0
end

#clone

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 33

def clone
  Comment.new self
end

#node_type

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 75

def node_type
  :comment
end

#write(output, indent = -1,, transitive = false, ie_hack = false)

DEPRECATED

See Formatters

output

Where to write the string

indent

An integer. If -1, no indenting will be used; otherwise, the indentation will be this number of spaces, and children will be indented an additional amount.

transitive

Ignored by this class. The contents of comments are never modified.

ie_hack

Needed for conformity to the child API, but not used by this class.

[ GitHub ]

  
# File 'lib/rexml/comment.rb', line 50

def write( output, indent=-1, transitive=false, ie_hack=false )
  Kernel.warn("Comment.write is deprecated.  See REXML::Formatters", uplevel: 1)
  indent( output, indent )
  output << START
  output << @string
  output << STOP
end