aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2013-01-06 18:59:27 +0200
committerBogdan Gusiev <agresso@gmail.com>2013-01-06 18:59:27 +0200
commit046e27a7338f2961c10e9d133e0e2229b51c2ba8 (patch)
tree6a114d8e319ac87be8cabbd28f16b8dfaae91c2b /activesupport
parent253cdc8b5b9a627287491039e11ae2381d5f0fe8 (diff)
downloadrails-046e27a7338f2961c10e9d133e0e2229b51c2ba8.tar.gz
rails-046e27a7338f2961c10e9d133e0e2229b51c2ba8.tar.bz2
rails-046e27a7338f2961c10e9d133e0e2229b51c2ba8.zip
Simplify code in AS json encoder
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb23
1 files changed, 8 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 832d1ce6d5..b3475c2569 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -38,7 +38,6 @@ module ActiveSupport
class CircularReferenceError < StandardError; end
class Encoder
- attr_reader :options
def initialize(options = nil)
@options = options || {}
@@ -63,9 +62,9 @@ module ActiveSupport
if value.is_a?(Array) || value.is_a?(Hash)
# hashes and arrays need to get encoder in the options, so that
# they can detect circular references.
- options.merge(:encoder => self)
+ @options.merge(:encoder => self)
else
- options.dup
+ @options.dup
end
end
@@ -253,18 +252,6 @@ end
module Enumerable
def as_json(options = nil) #:nodoc:
- to_a.as_json(options)
- end
-end
-
-class Range
- def as_json(options = nil) #:nodoc:
- to_s
- end
-end
-
-class Array
- def as_json(options = nil) #:nodoc:
# use encoder as a proxy to call as_json on all elements, to protect from circular references
encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options)
map { |v| encoder.as_json(v, options) }
@@ -276,6 +263,12 @@ class Array
end
end
+class Range
+ def as_json(options = nil) #:nodoc:
+ to_s
+ end
+end
+
class Hash
def as_json(options = nil) #:nodoc:
# create a subset of the hash by applying :only or :except