From 36de9eadaa9193cbc43a501aa345636d77d3b5c1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Jan 2019 14:36:00 -0800 Subject: [PATCH] Duration#coerce should always return a Scalar This speeds up Range.new(x, y).step(Duration).each { ... } Fixes #34888 --- activesupport/lib/active_support/duration.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 314c926ac0..97b4634d7b 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -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