From: Shri Borde Date: 2009-03-16T15:47:40+09:00 Subject: [ruby-core:22909] Which YAML::Syck types/methods are required by the spec? --_000_710DF26F214D2B4BB94287123FFE980A2E0D35FCDBNAEXMSGC104re_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I assume that most of the types under YAML::Syck are supposed to be impleme= ntation details, right? Assuming this is correct, some of those types are actually used by existing= Ruby code, mainly with YAML.quick_emit. In the real-world Ruby snippet bel= ow, the Ruby code uses YAML::Syck in two ways: 1. It passes an instance of YAML::Syck::Emitter as an argument to YAM= L.quick_parse 2. It calls YAML::Syck::Out#map. require "yaml" class B def to_yaml emitter YAML.quick_emit(object_id, emitter) do |out| out.map("tag:ruby.yaml.org,2002:object:B", to_yaml_style) do |map| map.add("b_attr", "some value") end end end end If you look at the extended version of the code at the end (also at http://= gist.github.com/79760# with color coding), you will see the details of the = types of the values used in the snippet. Given that existing Ruby code deal= s with some parts of YAML::Syck, its not clear what is left as an implement= ation detail, and what is required by the spec. It seems like YAML::Syck::Emitter and YAML::Syck::Out should both include (= new) modules like YAML::BaseEmitter and YAML::BaseOutputter which will have= the formal API that all Ruby implementations need to support. The pattern = would be the same as YAML::Syck::Map including YAML::BaseNode today. Does t= his sound right, and if so, should I open a bug to track this issue for Rub= y 1.9? Also, YAML::Syck::Emitter and YAML::Syck::Out have a number of methods. I h= ave not seen any uses of these methods, but I havent really used yaml much = either. Does anyone know if any of these other methods are actually used by= Ruby code? Thanks, Shri require "yaml" class A def initialize @b =3D B.new end end class B def to_yaml emitter puts emitter.class # YAML::Syck::Emitter puts emitter.class.ancestors.inspect # [YAML::Syck::Emitter, Object, Ke= rnel] puts (emitter.methods - Object.new.methods).sort.inspect # ["emit", "le= vel", "level=3D", "node_export", "reset", "set_resolver"] YAML.quick_emit(object_id, emitter) do |out| puts out.class # YAML::Syck::Out puts out.class.ancestors.inspect # [YAML::Syck::Out, Object, Kernel] puts (out.methods - Object.new.methods).sort.inspect # ["emitter", "e= mitter=3D", "map", "scalar", "seq"] out.map("tag:ruby.yaml.org,2002:object:B", to_yaml_style) do |map| puts map.class # YAML::Syck::Map puts map.class.ancestors.inspect # [YAML::Syck::Map, YAML::Syck::No= de, YAML::BaseNode, Object, Kernel] puts (map.methods - Object.new.methods).sort.inspect # ... map.add("b_attr", "some value") end end end end a =3D A.new a.to_yaml --_000_710DF26F214D2B4BB94287123FFE980A2E0D35FCDBNAEXMSGC104re_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I assume that most of the types under YAML::Syck are s= upposed to be implementation details, right?

 

Assuming this is correct, some of those types are actu= ally used by existing Ruby code, mainly with YAML.quick_emit. In the real-world = Ruby snippet below, the Ruby code uses YAML::Syck in two ways:

1.&n= bsp;      It passes an instance of YAML::Syck::Emitter as an argument to YAML.quick_parse

2.&n= bsp;      It calls YAML::Syck::Out#map.

 

require "yaml"

 

class B

  def to_yaml emitter

    YAML.quick_emit(object_id, emitter)= do |out|

      out.map("tag:ruby.yaml.org,2002:object:B", to_yaml_style) do |map= |

        map.add("b_attr", "some value")

      end

    end

  end

end

 

If you look at the extended version of the code at the= end (also at http://gist.github.com/79760#<= /a> with color coding), you will see the details of the types of the values use= d in the snippet. Given that existing Ruby code deals with some parts of YAML::S= yck, its not clear what is left as an implementation detail, and what is require= d by the spec.

 

It seems like YAML::Syck::Emitter and YAML::Syck::Out = should both include (new) modules like YAML::BaseEmitter and YAML::BaseOutputter w= hich will have the formal API that all Ruby implementations need to support. The pattern would be the same as YAML::Syck::Map including YAML::BaseNode today= . Does this sound right, and if so, should I open a bug to track this issue for Ru= by 1.9?

 

Also, YAML::Syck::Emitter and YAML::Syck::Out have a n= umber of methods. I have not seen any uses of these methods, but I havent really = used yaml much either. Does anyone know if any of these other methods are actual= ly used by Ruby code?

 

Thanks,

Shri

 

 

require "yaml"

 

class A

  def initialize

    @b =3D B.new

  end

end

 

class B

  def to_yaml emitter

    puts emitter.class # YAML::Syck::Em= itter

    puts emitter.class.ancestors.inspec= t # [YAML::Syck::Emitter, Object, Kernel]

    puts (emitter.methods - Object.new.methods).sort.inspect # ["emit", "level", "level=3D", "node_export", "reset", "set= _resolver"]

 

    YAML.quick_emit(object_id, emitter)= do |out|

      puts out.class # YAML::Syck::Out

      puts out.class.ancestors.inspect # [YAML::Syck::Out, Object, Kernel]<= /p>

      puts (out.methods - Object.new.methods).sort.inspect # ["emitter", "emitter=3D&q= uot;, "map", "scalar", "seq"]

 

      out.map("tag:ruby.yaml.org,2002:object:B", to_yaml_style) do |map= |

        puts map.cl= ass # YAML::Syck::Map

        puts map.class.ancestors.inspect # [YAML::Syck::Map, YAML::Syck::Node, YAML::BaseNode, Object, Kernel]

        puts (map.m= ethods - Object.new.methods).sort.inspect # ...

     

        map.add("b_attr", "some value")

      end

    end

  end

end

 

a =3D A.new

a.to_yaml

 

 

--_000_710DF26F214D2B4BB94287123FFE980A2E0D35FCDBNAEXMSGC104re_--