Skip to content

Instantly share code, notes, and snippets.

@matsadler
Created July 15, 2009 09:04
Show Gist options
  • Save matsadler/147593 to your computer and use it in GitHub Desktop.
Save matsadler/147593 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_record'
class Salutations
attr_accessor :greeting, :farewell
def initialize(greeting, farewell)
@greeting = greeting
@farewell = farewell
end
include ActiveRecord::Serialization
def self.inheritance_column
end
def self.serialized_attributes
{}
end
def self.columns_hash
type_struct = Struct.new(:type)
string_type = type_struct.new(:string)
{"greeting" => string_type, "farewell" => string_type}
end
def attribute_names
["greeting", "farewell"]
end
end
s = Salutations.new("hello", "goodbye")
s.to_xml
#=> <?xml version="1.0" encoding="UTF-8"?>
# <salutations>
# <greeting>hello</greeting>
# <farewell>goodbye</farewell>
# </salutations>
s.to_json
#=> {"greeting": "hello", "farewell": "goodbye"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment