Created
February 2, 2012 10:59
-
-
Save andrewn/1722895 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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