1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Duration#coerce should always return a Scalar

This speeds up Range.new(x, y).step(Duration).each { ... }

Fixes #34888
This commit is contained in:
Aaron Patterson 2019-01-08 14:36:00 -08:00
parent 80c7038bbc
commit 36de9eadaa
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6

View file

@ -214,8 +214,11 @@ module ActiveSupport
end
def coerce(other) #:nodoc:
if Scalar === other
case other
when Scalar
[other, self]
when Duration
[Scalar.new(other.value), self]
else
[Scalar.new(other), self]
end