Skip to content
  • Alberto Mota's avatar
    afa83350
    Deprecates `Enumerable#sum` and `Array#sum` · afa83350
    Alberto Mota authored
    Ruby (2.4+) includes a native implementation of `sum` with significant
    performance gains. Rails 7.1 will be removing `Enumerable#sum` and
    `Array#sum` in favor of Ruby's native implementation.
    
    This commit adds a deprecation warning to calls with non-numeric
    arguments without a suitable initial argument as those will be required
    once Rails removes this functionality.
    
    Some examples that will now trigger a deprecation warning:
        >> %w[foo bar].sum
        >> [[1, 2], [3, 4, 5]].sum
    
    To avoid the deprecation warning they should now invoked as follows:
        >> %w[foo bar].sum('')
        >> [[1, 2], [3, 4, 5]].sum([])
    
    In order to prepare for the deprecation on Rails 7.1, it also
    deprecates `[nil].sum == 0`, which in Ruby's native implementation
    throws a `TypeError`.
    afa83350
    Deprecates `Enumerable#sum` and `Array#sum`
    Alberto Mota authored
    Ruby (2.4+) includes a native implementation of `sum` with significant
    performance gains. Rails 7.1 will be removing `Enumerable#sum` and
    `Array#sum` in favor of Ruby's native implementation.
    
    This commit adds a deprecation warning to calls with non-numeric
    arguments without a suitable initial argument as those will be required
    once Rails removes this functionality.
    
    Some examples that will now trigger a deprecation warning:
        >> %w[foo bar].sum
        >> [[1, 2], [3, 4, 5]].sum
    
    To avoid the deprecation warning they should now invoked as follows:
        >> %w[foo bar].sum('')
        >> [[1, 2], [3, 4, 5]].sum([])
    
    In order to prepare for the deprecation on Rails 7.1, it also
    deprecates `[nil].sum == 0`, which in Ruby's native implementation
    throws a `TypeError`.
Loading