Skip to content

Instantly share code, notes, and snippets.

@sbwoodside
Created September 2, 2009 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbwoodside/179530 to your computer and use it in GitHub Desktop.
Save sbwoodside/179530 to your computer and use it in GitHub Desktop.
module ActiveRecord::Serialization
def self.from_xml(xml)
the_class = Hash.from_xml(xml).keys.first.singularize.camelize.constantize # singularize does nothing if already singular
array_or_hash = Hash.from_xml(xml).values.first
array_or_hash.class == Array ? array_or_hash.map { |hash| the_class.new( hash ) } : the_class.new( array_or_hash )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment