Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created July 8, 2013 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashmoran/5950325 to your computer and use it in GitHub Desktop.
Save ashmoran/5950325 to your computer and use it in GitHub Desktop.
Recursive Hash/Array -> OpenStruct
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
@aldrienht
Copy link

Thanks to this gist :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment