Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • psych/lib/psych/coder.rb

Psych::Coder

If an object defines encode_with, then an instance of Psych::Coder will be passed to the method when the object is being serialized. The Coder automatically assumes a Psych::Nodes::Mapping is being emitted. Other objects like Sequence and Scalar may be emitted if seq= or scalar= are called, respectively.

Attributes

implicit[RW]
object[RW]
seq[R]
style[RW]
tag[RW]
type[R]

Public Class Methods

new(tag) click to toggle source
 
               # File psych/lib/psych/coder.rb, line 12
def initialize tag
  @map      = {}
  @seq      = []
  @implicit = false
  @type     = :map
  @tag      = tag
  @style    = Psych::Nodes::Mapping::BLOCK
  @scalar   = nil
  @object   = nil
end
            

Public Instance Methods

[](k) click to toggle source
 
               # File psych/lib/psych/coder.rb, line 83
def [] k
  @type = :map
  @map[k]
end
            
[]=(k, v) click to toggle source
 
               # File psych/lib/psych/coder.rb, line 77
def []= k, v
  @type = :map
  @map[k] = v
end
            
Also aliased as: add
add(k, v) click to toggle source
Alias for: []=
map(tag = @tag, style = @style) click to toggle source

Emit a map. The coder will be yielded to the block.

 
               # File psych/lib/psych/coder.rb, line 33
def map tag = @tag, style = @style
  @tag   = tag
  @style = style
  yield self if block_given?
  @map
end
            
map=(map) click to toggle source

Emit a map with value

 
               # File psych/lib/psych/coder.rb, line 72
def map= map
  @type = :map
  @map  = map
end
            
represent_map(tag, map) click to toggle source

Emit a sequence with map and tag

 
               # File psych/lib/psych/coder.rb, line 53
def represent_map tag, map
  @tag = tag
  self.map = map
end
            
represent_object(tag, obj) click to toggle source

Emit an arbitrary object obj and tag

 
               # File psych/lib/psych/coder.rb, line 59
def represent_object tag, obj
  @tag    = tag
  @type   = :object
  @object = obj
end
            
represent_scalar(tag, value) click to toggle source

Emit a scalar with value and tag

 
               # File psych/lib/psych/coder.rb, line 41
def represent_scalar tag, value
  self.tag    = tag
  self.scalar = value
end
            
represent_seq(tag, list) click to toggle source

Emit a sequence with list and tag

 
               # File psych/lib/psych/coder.rb, line 47
def represent_seq tag, list
  @tag = tag
  self.seq = list
end
            
scalar(*args) click to toggle source
 
               # File psych/lib/psych/coder.rb, line 23
def scalar *args
  if args.length > 0
    warn "#{caller[0]}: Coder#scalar(a,b,c) is deprecated" if $VERBOSE
    @tag, @scalar, _ = args
    @type = :scalar
  end
  @scalar
end
            
scalar=(value) click to toggle source

Emit a scalar with value

 
               # File psych/lib/psych/coder.rb, line 66
def scalar= value
  @type   = :scalar
  @scalar = value
end
            
seq=(list) click to toggle source

Emit a sequence of list

 
               # File psych/lib/psych/coder.rb, line 89
def seq= list
  @type = :seq
  @seq  = list
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.