diff options
Diffstat (limited to 'activesupport/lib/active_support/json/encoders/hash.rb')
-rw-r--r-- | activesupport/lib/active_support/json/encoders/hash.rb | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/json/encoders/hash.rb b/activesupport/lib/active_support/json/encoders/hash.rb index 16dc8337f5..e38b4f3e16 100644 --- a/activesupport/lib/active_support/json/encoders/hash.rb +++ b/activesupport/lib/active_support/json/encoders/hash.rb @@ -31,17 +31,16 @@ 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]) + if except = options[:except] + hash_keys = hash_keys - Array.wrap(except) + elsif only = options[:only] + hash_keys = hash_keys & Array.wrap(only) end - returning result = '{' do - result << hash_keys.map do |key| - "#{ActiveSupport::JSON.encode(key.to_s)}: #{ActiveSupport::JSON.encode(self[key], options)}" - end * ', ' - result << '}' - end + result = '{' + result << hash_keys.map do |key| + "#{ActiveSupport::JSON.encode(key.to_s)}: #{ActiveSupport::JSON.encode(self[key], options)}" + end * ', ' + result << '}' end end |