Brian Buckley wrote: >>class Foo >> attr_reader :name >> def initialize name >> @name = name >> end >> >> def is_complex_yaml? >> false >> end >> def to_yaml( opts = {} ) >> YAML::quick_emit( nil, opts ) { |out| >> out << "!ruby/foo " >> self.name.to_yaml( :Emitter => out ) >> } >> end >>end >>YAML.add_ruby_type(/^foo/) do |type, val| >> subtype, subclass = YAML.read_type_class(type, Foo) >> val.split(/::/).inject(Object) { |p, n| p.const_get(n)} >>end > > > Joel, I don't yet fully understand your code Where can I find > explanations of is_complex_yaml?, add_ruby_type, read_type_class and > quick_emit? (My original class doesn't actually have a "name" > attribute but maybe once I understand this better I can adapt). > > Brian Buckley > I hope I'm wrong, but I don't think those are really documented anywhere. I got to this point by adapting code in rubytypes.rb in the YAML lib files. You could replace "name" with anything else that is YAML-able and persistently identifies your objects. I *think* is_complex_yaml? controls whether the object is persisted to a single line of text or not. My guess is that add_ruby_type(/^foo/) makes YAML recognize things in the file that look like "!ruby/foo ...". -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407