Skip to content

Instantly share code, notes, and snippets.

@ream88
Created June 16, 2011 08:30
Show Gist options
  • Save ream88/1028892 to your computer and use it in GitHub Desktop.
Save ream88/1028892 to your computer and use it in GitHub Desktop.
Hash to OpenStruct (recursive)
class Hash
def to_ostruct
OpenStruct.new(Hash[*collect do |key, value|
[key, value.is_a?(Hash) ? value.to_ostruct : value]
end.flatten])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment