class Psych::Coder
如果一个对象定义了 encode_with 方法,那么当该对象被序列化时,会传递一个 Psych::Coder 的实例给该方法。 Coder 默认会认为正在发出一个 Psych::Nodes::Mapping。 如果分别调用了 seq= 或 scalar=,则可以发出诸如 Sequence 和 Scalar 等其他对象。
属性
公共类方法
源码
# File ext/psych/lib/psych/coder.rb, line 13 def initialize tag @map = {} @seq = [] @implicit = false @type = :map @tag = tag @style = Psych::Nodes::Mapping::BLOCK @scalar = nil @object = nil end
公共实例方法
源码
# File ext/psych/lib/psych/coder.rb, line 34 def map tag = @tag, style = @style @tag = tag @style = style yield self if block_given? @map end
发出一个映射。coder 将被传递给代码块。
源码
# File ext/psych/lib/psych/coder.rb, line 73 def map= map @type = :map @map = map end
发出带有 value 的映射
源码
# File ext/psych/lib/psych/coder.rb, line 54 def represent_map tag, map @tag = tag self.map = map end
发出带有 map 和 tag 的序列
源码
# File ext/psych/lib/psych/coder.rb, line 60 def represent_object tag, obj @tag = tag @type = :object @object = obj end
发出任意对象 obj 和 tag
源码
# File ext/psych/lib/psych/coder.rb, line 42 def represent_scalar tag, value self.tag = tag self.scalar = value end
发出带有 value 和 tag 的标量
源码
# File ext/psych/lib/psych/coder.rb, line 48 def represent_seq tag, list @tag = tag self.seq = list end
发出带有 list 和 tag 的序列
源码
# 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
源码
# File ext/psych/lib/psych/coder.rb, line 67 def scalar= value @type = :scalar @scalar = value end
发出带有 value 的标量
源码
# File ext/psych/lib/psych/coder.rb, line 90 def seq= list @type = :seq @seq = list end
发出 list 的序列