Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created February 2, 2012 10:59
Show Gist options
  • Save andrewn/1722895 to your computer and use it in GitHub Desktop.
Save andrewn/1722895 to your computer and use it in GitHub Desktop.
def hash_to_ostruct(object)
return case object
when Hash
object = object.clone
object.each do |key, value|
object[key] = hash_to_ostruct(value)
end
OpenStruct.new(object)
when Array
object = object.clone
object.map! { |i| hash_to_ostruct(i) }
else
object
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment