Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

use #to_s to convert Range to json #4250

Merged
merged 1 commit into from

2 participants

@lest

Original issue #4239

@fxn fxn merged commit e04232e into rails:master
@arunagw arunagw referenced this pull request
Closed

Range.as_json #4239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 1, 2012
  1. @lest
This page is out of date. Refresh to see the latest.
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") ]]
Something went wrong with that request. Please try again.