提交 8d640851 编写于 作者: J Jeremy Kemper

Only Object to_json alias is needed. Prefer nil options.

上级 be7e21a8
......@@ -1188,8 +1188,6 @@ def rails_to_json(options = nil)
@variable
end
alias to_json rails_to_json
private
def append_to_function_chain!(call)
@generator << @variable if @empty
......
......@@ -18,6 +18,4 @@ def rails_to_json(options = nil)
%("#{strftime("%Y/%m/%d")}")
end
end
alias to_json rails_to_json
end
......@@ -18,6 +18,4 @@ def rails_to_json(options = nil)
strftime('"%Y/%m/%d %H:%M:%S %z"')
end
end
alias to_json rails_to_json
end
......@@ -6,9 +6,7 @@ module Enumerable
# # => users.to_json(:only => :name)
#
# will pass the <tt>:only => :name</tt> option to each user.
def rails_to_json(options = {}) #:nodoc:
def rails_to_json(options = nil) #:nodoc:
"[#{map { |value| ActiveSupport::JSON.encode(value, options) } * ','}]"
end
alias to_json rails_to_json
end
......@@ -2,6 +2,4 @@ class FalseClass
def rails_to_json(options = nil) #:nodoc:
'false'
end
alias to_json rails_to_json
end
......@@ -30,13 +30,15 @@ class Hash
# would pass the <tt>:include => :posts</tt> option to <tt>users</tt>,
# allowing the posts association in the User model to be converted to JSON
# as well.
def rails_to_json(options = {}) #:nodoc:
def rails_to_json(options = nil) #:nodoc:
hash_keys = self.keys
if except = options[:except]
hash_keys = hash_keys - Array.wrap(except)
elsif only = options[:only]
hash_keys = hash_keys & Array.wrap(only)
if options
if except = options[:except]
hash_keys = hash_keys - Array.wrap(except)
elsif only = options[:only]
hash_keys = hash_keys & Array.wrap(only)
end
end
result = '{'
......@@ -45,6 +47,4 @@ def rails_to_json(options = {}) #:nodoc:
end * ','
result << '}'
end
alias to_json rails_to_json
end
......@@ -2,6 +2,4 @@ class NilClass
def rails_to_json(options = nil) #:nodoc:
'null'
end
alias to_json rails_to_json
end
......@@ -2,6 +2,4 @@ class Numeric
def rails_to_json(options = nil) #:nodoc:
to_s
end
alias to_json rails_to_json
end
......@@ -2,7 +2,7 @@
class Object
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
def rails_to_json(options = {})
def rails_to_json(options = nil)
ActiveSupport::JSON.encode(instance_values, options)
end
......
......@@ -2,6 +2,4 @@ class Regexp
def rails_to_json(options = nil) #:nodoc:
inspect
end
alias to_json rails_to_json
end
......@@ -33,6 +33,4 @@ def rails_to_json(options = nil) #:nodoc:
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
} + '"'
end
alias to_json rails_to_json
end
class Symbol
def rails_to_json(options = {}) #:nodoc:
def rails_to_json(options = nil) #:nodoc:
ActiveSupport::JSON.encode(to_s, options)
end
alias to_json rails_to_json
end
......@@ -20,6 +20,4 @@ def rails_to_json(options = nil)
%("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
end
end
alias to_json rails_to_json
end
......@@ -2,6 +2,4 @@ class TrueClass
def rails_to_json(options = nil) #:nodoc:
'true'
end
alias to_json rails_to_json
end
......@@ -4,7 +4,8 @@ class CircularReferenceError < StandardError
end
# Converts a Ruby object into a JSON string.
def self.encode(value, options = {})
def self.encode(value, options = nil)
options ||= {}
seen = (options[:seen] ||= [])
raise CircularReferenceError, 'object references itself' if seen.include?(value.object_id)
seen << value.object_id
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册