Created
August 29, 2010 15:40
-
-
Save stan/556395 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
# http://snippets.dzone.com/posts/show/7312 | |
require 'ostruct' | |
class MoreOpenStruct < OpenStruct | |
def _to_hash | |
h = @table | |
#handles nested structures | |
h.each do |k,v| | |
if v.class == MoreOpenStruct | |
h[k] = v._to_hash | |
end | |
end | |
return h | |
end | |
def _table | |
@table #table is the hash structure used in OpenStruct | |
end | |
def _manual_set(hash) | |
if hash && (hash.class == Hash) | |
for k,v in hash | |
@table[k.to_sym] = v | |
new_ostruct_member(k) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment