Created
March 16, 2009 06:36
-
-
Save shri-zz/79760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "yaml" | |
class A | |
def initialize | |
@b = 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, Kernel] | |
puts (emitter.methods - Object.new.methods).sort.inspect # ["emit", "level", "level=", "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", "emitter=", "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::Node, YAML::BaseNode, Object, Kernel] | |
puts (map.methods - Object.new.methods).sort.inspect # ... | |
map.add("b_attr", "some value") | |
end | |
end | |
end | |
end | |
a = A.new | |
a.to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment