diff options
author | Daniel Neighman <has.sox@gmail.com> | 2010-06-15 14:16:25 +0800 |
---|---|---|
committer | Michael Bleigh <michael@intridea.com> | 2010-06-22 22:00:39 +0800 |
commit | 0c85e9482f0ca0232d7cf7cf6577a359ea07ffed (patch) | |
tree | 34a2dd820c3e78721b3931a87b8a91b28f1091eb /lib/hashie/hash.rb | |
parent | a026498fb732eeb8ad9bdb11bf28d21d8c0e3467 (diff) | |
download | hashie-0c85e9482f0ca0232d7cf7cf6577a359ea07ffed.tar.gz |
Adds a fix for json generation
Diffstat (limited to 'lib/hashie/hash.rb')
-rw-r--r-- | lib/hashie/hash.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/hashie/hash.rb b/lib/hashie/hash.rb index d13a58b..906563c 100644 --- a/lib/hashie/hash.rb +++ b/lib/hashie/hash.rb @@ -4,5 +4,19 @@ module Hashie # not be available in all libraries. class Hash < Hash include Hashie::HashExtensions + + # Converts a mash back to a hash (with stringified keys) + def to_hash + out = {} + keys.each do |k| + out[k] = Hashie::Hash === self[k] ? self[k].to_hash : self[k] + end + out + end + + # The C geneartor for the json gem doesn't like mashies + def to_json + to_hash.to_json + end end -end
\ No newline at end of file +end |