use #to_s to convert Range to json

This commit is contained in:
Sergey Nartimov 2012-01-01 20:16:10 +03:00
parent f3e079e8b5
commit dc05914be7
2 changed files with 8 additions and 0 deletions

View File

@ -206,6 +206,10 @@ module Enumerable
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 File

@ -38,6 +38,10 @@ class TestJSONEncoding < Test::Unit::TestCase
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") ]]