Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set the default options value for as_json in the encoder object.

  • Loading branch information...
commit 37b9594a8e08916e1e9ae9a6aaffc13ef516ad11 1 parent afeb897
@josevalim josevalim authored
View
2  activesupport/lib/active_support/core_ext/object/to_json.rb
@@ -12,7 +12,7 @@
[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
klass.class_eval <<-RUBY, __FILE__, __LINE__
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
- def to_json(options = {})
+ def to_json(options = nil)
ActiveSupport::JSON.encode(self, options)
end
RUBY
View
4 activesupport/lib/active_support/json/encoding.rb
@@ -38,7 +38,7 @@ class Encoder
attr_reader :options
def initialize(options = nil)
- @options = options
+ @options = options || {}
@seen = Set.new
end
@@ -59,7 +59,7 @@ def as_json(value)
def options_for(value)
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
end
Please sign in to comment.
Something went wrong with that request. Please try again.