I've got a class that serializes data. I may want to serialize this data as JSON, or perhaps YAML. Can I cleanly swap YAML for JSON objects in this case? I was hoping I could do something like the following. Is it a pipe dream?
FORMATS = {
:json => JSON,
:yaml => YAML,
}
def serialize(data, format)
FORMATS[format].serialize(data)
end