1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/lib/active_support/json/encoders/hash.rb

19 lines
459 B
Ruby
Raw Normal View History

class Hash
def to_json(options = {}) #:nodoc:
hash_keys = self.keys
if options[:except]
hash_keys = hash_keys - Array(options[:except])
elsif options[:only]
hash_keys = hash_keys & Array(options[:only])
end
returning result = '{' do
result << hash_keys.map do |key|
"#{ActiveSupport::JSON.encode(key)}: #{ActiveSupport::JSON.encode(self[key], options)}"
end * ', '
result << '}'
end
end
end