Created
July 8, 2013 16:30
-
-
Save ashmoran/5950325 to your computer and use it in GitHub Desktop.
Recursive Hash/Array -> OpenStruct
This file contains 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 recursive_ostruct(object) | |
case object | |
when Hash | |
hash = {}; object.each{|k,v| hash[k] = recursive_ostruct(v)} | |
OpenStruct.new(hash) | |
when Array | |
object.map {|e| recursive_ostruct(e) } | |
else | |
object | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to this gist :)