Skip to content
Browse files

use #to_s to convert Range to json

  • Loading branch information...
1 parent f3e079e commit dc05914be766583a22c959b2df64cfd2dfe88732 @lest committed
Showing with 8 additions and 0 deletions.
  1. +4 −0 activesupport/lib/active_support/json/encoding.rb
  2. +4 −0 activesupport/test/json/encoding_test.rb
View
4 activesupport/lib/active_support/json/encoding.rb
@@ -206,6 +206,10 @@ def as_json(options = nil) #:nodoc:
end
end
+class Range
+ def as_json(options = nil) to_s end #:nodoc:
+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
View
4 activesupport/test/json/encoding_test.rb
@@ -38,6 +38,10 @@ def as_json(options)
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\",\"b\",\"c\"]) ],
[ [1, 'a', :b, nil, false], %([1,\"a\",\"b\",null,false]) ]]
+ RangeTests = [[ 1..2, %("1..2")],
+ [ 1...2, %("1...2")],
+ [ 1.5..2.5, %("1.5..2.5")]]
+
SymbolTests = [[ :a, %("a") ],
[ :this, %("this") ],
[ :"a b", %("a b") ]]

0 comments on commit dc05914

Please sign in to comment.
Something went wrong with that request. Please try again.