Created
July 15, 2009 09:04
-
-
Save matsadler/147593 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 '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