Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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