Skip to content

Instantly share code, notes, and snippets.

@jhiemer
Created March 8, 2014 09:59
Show Gist options
  • Save jhiemer/c325d668f4cea9c35484 to your computer and use it in GitHub Desktop.
Save jhiemer/c325d668f4cea9c35484 to your computer and use it in GitHub Desktop.
def ostruct2hashes(object)
return case object
when OpenStruct
object = object.clone
object.each do |key, value|
object[key] = ostruct2hashes(value)
end
object.marshal_dump
when Array
object = object.clone
object.map! { |i| ostruct2hashes(i) }
else
object
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment