Skip to content

Commit 4a78dae

Browse files
committed
Revert rails_to_json -> to_json so we don't break compatibility
[#2753 state:resolved]
1 parent 4b4164e commit 4a78dae

File tree

17 files changed

+59
-26
lines changed

17 files changed

+59
-26
lines changed

activesupport/lib/active_support/json/encoders/date.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Date
1111
# # With ActiveSupport.use_standard_json_time_format = false
1212
# Date.new(2005,2,1).to_json
1313
# # => "2005/02/01"
14-
def rails_to_json(options = nil)
14+
def to_json(options = nil)
1515
if ActiveSupport.use_standard_json_time_format
1616
%("#{strftime("%Y-%m-%d")}")
1717
else

activesupport/lib/active_support/json/encoders/date_time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DateTime
1111
# # With ActiveSupport.use_standard_json_time_format = false
1212
# DateTime.civil(2005,2,1,15,15,10).to_json
1313
# # => "2005/02/01 15:15:10 +0000"
14-
def rails_to_json(options = nil)
14+
def to_json(options = nil)
1515
if ActiveSupport.use_standard_json_time_format
1616
xmlschema.inspect
1717
else

activesupport/lib/active_support/json/encoders/enumerable.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ module Enumerable
66
# # => users.to_json(:only => :name)
77
#
88
# will pass the <tt>:only => :name</tt> option to each user.
9-
def rails_to_json(options = nil) #:nodoc:
9+
def to_json(options = nil) #:nodoc:
10+
to_a.to_json(options)
11+
end
12+
end
13+
14+
class Array
15+
def to_json(options = nil) #:nodoc:
1016
"[#{map { |value| ActiveSupport::JSON.encode(value, options) } * ','}]"
1117
end
1218
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class FalseClass
2-
def rails_to_json(options = nil) #:nodoc:
2+
def to_json(options = nil) #:nodoc:
33
'false'
44
end
55
end

activesupport/lib/active_support/json/encoders/hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Hash
2828
# would pass the <tt>:include => :posts</tt> option to <tt>users</tt>,
2929
# allowing the posts association in the User model to be converted to JSON
3030
# as well.
31-
def rails_to_json(options = nil) #:nodoc:
31+
def to_json(options = nil) #:nodoc:
3232
hash_keys = self.keys
3333

3434
if options
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class NilClass
2-
def rails_to_json(options = nil) #:nodoc:
2+
def to_json(options = nil) #:nodoc:
33
'null'
44
end
55
end
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
class Numeric
2-
def rails_to_json(options = nil) #:nodoc:
2+
def to_json(options = nil) #:nodoc:
3+
to_s
4+
end
5+
end
6+
7+
class Float
8+
def to_json(options = nil) #:nodoc:
9+
to_s
10+
end
11+
end
12+
13+
class Integer
14+
def to_json(options = nil) #:nodoc:
315
to_s
416
end
517
end
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
class Object
22
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
3-
def rails_to_json(options = nil)
3+
def to_json(options = nil)
44
ActiveSupport::JSON.encode(instance_values, options)
55
end
6-
7-
def to_json(*args)
8-
rails_to_json(*args)
9-
end
106
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Regexp
2-
def rails_to_json(options = nil) #:nodoc:
2+
def to_json(options = nil) #:nodoc:
33
inspect
44
end
55
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class String
2-
def rails_to_json(options = nil) #:nodoc:
2+
def to_json(options = nil) #:nodoc:
33
ActiveSupport::JSON::Encoding.escape(self)
44
end
55
end

0 commit comments

Comments
 (0)