Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use #to_s to convert Range to json

  • Loading branch information...
commit dc05914be766583a22c959b2df64cfd2dfe88732 1 parent f3e079e
@lest lest authored
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") ]]
Please sign in to comment.
Something went wrong with that request. Please try again.