B
Ben Giddings
Hi all,
I'm trying to understand how to write a custom YAML emitter. As fun
and interesting as Why's documentation is, I don't quite get how to do
what I need.
What I'm looking for is a way of avoiding emitting certain instance
variables. Say I have a class like this:
class Book
attr_accessor :title, :chapter_titles
attr_accessor :current_page
end
When I save it, I want to save the permanent features like "title" and
"chapter_titles", but I want to forget the current page.
I think the YAML representation would be something like:
--- !ruby/object:Bar
title: Fun with YAML
chapter_titles:
- your first yaml document
- daily yaml chores
- advanced yaml fun
From looking at "rubytypes.rb", it looks like if I redefine
"to_yaml_properties" to return ["@title", "@chapter_titles"] it should
work. But is this the right way? Is there another preferred way?
Ben
I'm trying to understand how to write a custom YAML emitter. As fun
and interesting as Why's documentation is, I don't quite get how to do
what I need.
What I'm looking for is a way of avoiding emitting certain instance
variables. Say I have a class like this:
class Book
attr_accessor :title, :chapter_titles
attr_accessor :current_page
end
When I save it, I want to save the permanent features like "title" and
"chapter_titles", but I want to forget the current page.
I think the YAML representation would be something like:
--- !ruby/object:Bar
title: Fun with YAML
chapter_titles:
- your first yaml document
- daily yaml chores
- advanced yaml fun
From looking at "rubytypes.rb", it looks like if I redefine
"to_yaml_properties" to return ["@title", "@chapter_titles"] it should
work. But is this the right way? Is there another preferred way?
Ben