From 0c85e9482f0ca0232d7cf7cf6577a359ea07ffed Mon Sep 17 00:00:00 2001 From: Daniel Neighman Date: Tue, 15 Jun 2010 14:16:25 +0800 Subject: Adds a fix for json generation --- lib/hashie/hash.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/hashie/hash.rb') 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 -- cgit v1.2.1