Skip to content

Commit

Permalink
Merge pull request #4250 from lest/range-json
Browse files Browse the repository at this point in the history
use #to_s to convert Range to json
  • Loading branch information
fxn committed Jan 2, 2012
2 parents 6de1b2a + dc05914 commit e04232e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activesupport/lib/active_support/json/encoding.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/json/encoding_test.rb
Expand Up @@ -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") ]]
Expand Down

0 comments on commit e04232e

Please sign in to comment.