Class: Psych::Coder
Overview
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.
Instance Attribute Summary collapse
- 
  
    
      #implicit  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute implicit. 
- 
  
    
      #object  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute object. 
- 
  
    
      #seq  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute seq. 
- 
  
    
      #style  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute style. 
- 
  
    
      #tag  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute tag. 
- 
  
    
      #type  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute type. 
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object (also: #add)
- 
  
    
      #initialize(tag)  ⇒ Coder 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Coder. 
- 
  
    
      #map(tag = @tag, style = @style) {|_self| ... } ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit a map. 
- 
  
    
      #map=(map)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit a map with value.
- 
  
    
      #represent_map(tag, map)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit a sequence with mapandtag.
- 
  
    
      #represent_object(tag, obj)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit an arbitrary object objandtag.
- 
  
    
      #represent_scalar(tag, value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit a scalar with valueandtag.
- 
  
    
      #represent_seq(tag, list)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit a sequence with listandtag.
- #scalar(*args) ⇒ Object
- 
  
    
      #scalar=(value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Emit a scalar with value.
Constructor Details
Instance Attribute Details
#implicit ⇒ Object
Returns the value of attribute implicit.
| 9 10 11 | # File 'lib/psych/coder.rb', line 9 def implicit @implicit end | 
#object ⇒ Object
Returns the value of attribute object.
| 9 10 11 | # File 'lib/psych/coder.rb', line 9 def object @object end | 
#seq ⇒ Object
Returns the value of attribute seq.
| 10 11 12 | # File 'lib/psych/coder.rb', line 10 def seq @seq end | 
#style ⇒ Object
Returns the value of attribute style.
| 9 10 11 | # File 'lib/psych/coder.rb', line 9 def style @style end | 
#tag ⇒ Object
Returns the value of attribute tag.
| 9 10 11 | # File 'lib/psych/coder.rb', line 9 def tag @tag end | 
#type ⇒ Object (readonly)
Returns the value of attribute type.
| 10 11 12 | # File 'lib/psych/coder.rb', line 10 def type @type end | 
Instance Method Details
#[](k) ⇒ Object
| 83 84 85 86 | # File 'lib/psych/coder.rb', line 83 def [] k @type = :map @map[k] end | 
#[]=(k, v) ⇒ Object Also known as: add
| 77 78 79 80 | # File 'lib/psych/coder.rb', line 77 def []= k, v @type = :map @map[k] = v end | 
#map(tag = @tag, style = @style) {|_self| ... } ⇒ Object
Emit a map. The coder will be yielded to the block.
| 33 34 35 36 37 38 | # File '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) ⇒ Object
Emit a map with value
| 72 73 74 75 | # File 'lib/psych/coder.rb', line 72 def map= map @type = :map @map = map end | 
#represent_map(tag, map) ⇒ Object
Emit a sequence with map and tag
| 53 54 55 56 | # File 'lib/psych/coder.rb', line 53 def represent_map tag, map @tag = tag self.map = map end | 
#represent_object(tag, obj) ⇒ Object
Emit an arbitrary object obj and tag
| 59 60 61 62 63 | # File 'lib/psych/coder.rb', line 59 def represent_object tag, obj @tag = tag @type = :object @object = obj end | 
#represent_scalar(tag, value) ⇒ Object
Emit a scalar with value and tag
| 41 42 43 44 | # File 'lib/psych/coder.rb', line 41 def represent_scalar tag, value self.tag = tag self.scalar = value end | 
#represent_seq(tag, list) ⇒ Object
Emit a sequence with list and tag
| 47 48 49 50 | # File 'lib/psych/coder.rb', line 47 def represent_seq tag, list @tag = tag self.seq = list end | 
#scalar(*args) ⇒ Object
| 23 24 25 26 27 28 29 30 | # File '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) ⇒ Object
Emit a scalar with value
| 66 67 68 69 | # File 'lib/psych/coder.rb', line 66 def scalar= value @type = :scalar @scalar = value end |