Skip to content

Commit 900dc32

Browse files
authored
Merge pull request rails#50211 from Shopify/delegate-as-module
Optimize many delegated methods on ActiveSupport::Duration
2 parents e1800cd + 8e1c1cc commit 900dc32

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

activesupport/lib/active_support/duration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module ActiveSupport
1414
class Duration
1515
class Scalar < Numeric # :nodoc:
1616
attr_reader :value
17-
delegate :to_i, :to_f, :to_s, to: :value
17+
delegate :to_i, :to_f, :to_s, to: :@value
1818

1919
def initialize(value)
2020
@value = value
@@ -221,6 +221,8 @@ def calculate_total_seconds(parts)
221221
end
222222
end
223223

224+
delegate :to_f, :positive?, :negative?, :zero?, :abs, to: :@value, as: Integer
225+
224226
def initialize(value, parts, variable = nil) # :nodoc:
225227
@value, @parts = value, parts
226228
@parts.reject! { |k, v| v.zero? } unless value == 0

0 commit comments

Comments
 (0)