Class: Psych::Coder
| Relationships & Source Files | |
| Inherits: | Object | 
| Defined in: | ext/psych/lib/psych/coder.rb | 
Overview
If an object defines encode_with, then an instance of Coder will be passed to the method when the object is being serialized.  The Coder automatically assumes a Nodes::Mapping is being emitted.  Other objects like Sequence and Scalar may be emitted if #seq= or #scalar= are called, respectively.
Class Method Summary
- .new(tag) ⇒ Coder constructor
Instance Attribute Summary
Instance Method Summary
- #[](k)
- #[]=(k, v) (also: #add)
- 
    
      #add(k, v)  
    
    Alias for #[]=. 
- 
    
      #map(tag = @tag, style = @style) {|_self| ... } 
    
    Emit a map. 
- 
    
      #map=(map)  
    
    Emit a map with value
- #represent_map(tag, map)
- 
    
      #represent_object(tag, obj)  
    
    Emit an arbitrary object objand #tag
- 
    
      #represent_scalar(tag, value)  
    
    Emit a scalar with valueand #tag
- 
    
      #represent_seq(tag, list)  
    
    Emit a sequence with listand #tag
- #scalar(*args)
- 
    
      #scalar=(value)  
    
    Emit a scalar with value
Constructor Details
    .new(tag)  ⇒ Coder 
  
Instance Attribute Details
#implicit (rw)
[ GitHub ]#object (rw)
[ GitHub ]#seq (rw)
[ GitHub ]# File 'ext/psych/lib/psych/coder.rb', line 11
attr_reader :type, :seq
#seq=(list) (rw)
Emit a sequence of list
# File 'ext/psych/lib/psych/coder.rb', line 90
def seq= list @type = :seq @seq = list end
#style (rw)
[ GitHub ]#tag (rw)
[ GitHub ]#type (readonly)
[ GitHub ]# File 'ext/psych/lib/psych/coder.rb', line 11
attr_reader :type, :seq
Instance Method Details
#[](k)
[ GitHub ]# File 'ext/psych/lib/psych/coder.rb', line 84
def [] k @type = :map @map[k] end
#[]=(k, v) Also known as: #add
[ GitHub ]# File 'ext/psych/lib/psych/coder.rb', line 78
def []= k, v @type = :map @map[k] = v end
#add(k, v)
Alias for #[]=.
# File 'ext/psych/lib/psych/coder.rb', line 82
alias :add :[]=
#map(tag = @tag, style = @style) {|_self| ... }
Emit a map. The coder will be yielded to the block.
#map=(map)
Emit a map with value
#represent_map(tag, map)
[ GitHub ]#represent_object(tag, obj)
Emit an arbitrary object obj and #tag
#represent_scalar(tag, value)
Emit a scalar with value and #tag
#represent_seq(tag, list)
Emit a sequence with list and #tag
#scalar(*args)
[ GitHub ]# File 'ext/psych/lib/psych/coder.rb', line 24
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)
Emit a scalar with value
# File 'ext/psych/lib/psych/coder.rb', line 67
def scalar= value @type = :scalar @scalar = value end