diff options
Diffstat (limited to 'activesupport/lib/active_support/json/encoders/hash.rb')
-rw-r--r-- | activesupport/lib/active_support/json/encoders/hash.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/json/encoders/hash.rb b/activesupport/lib/active_support/json/encoders/hash.rb new file mode 100644 index 0000000000..3654e10b2e --- /dev/null +++ b/activesupport/lib/active_support/json/encoders/hash.rb @@ -0,0 +1,12 @@ +class Hash + def to_json #:nodoc: + returning result = '{' do + result << map do |key, value| + key = ActiveSupport::JSON::Variable.new(key.to_s) if + ActiveSupport::JSON.can_unquote_identifier?(key) + "#{ActiveSupport::JSON.encode(key)}: #{ActiveSupport::JSON.encode(value)}" + end * ', ' + result << '}' + end + end +end |