This blog is part of our Rails 7 series.
Rails 7 deprecates Enumerable#sum to the calls with non-numeric arguments. To ignore the warning we should use a suitable initial argument.
Before Rails 7
=> %w[foo bar].sum
=> "foobar"
=> [[1, 2], [3, 4, 5]].sum
=> [1, 2, 3, 4, 5]
After Rails 7
=> %w[foo bar].sum
=> Rails 7.0 has deprecated Enumerable.sum in favor of Ruby's native implementation available since 2.4.
Sum of non-numeric elements requires an initial argument.
=> [[1, 2], [3, 4, 5]].sum
=> Rails 7.0 has deprecated Enumerable.sum in favor of Ruby's native implementation available since 2.4.
Sum of non-numeric elements requires an initial argument.
To avoid the deprecation warning, we should use suitable argument as below.
=> %w[foo bar].sum('')
=> "foobar"
=> [[1, 2], [3, 4, 5]].sum([])
=> [1, 2, 3, 4, 5]
Check out this pull request for more details.

Written byAashish Saini
Related blogs
- 01Rails 7.1 allows subscribing to transaction eventsJanuary 16, 2024 · Vishnu M
- 02Rails 7.1 adds path_params option to url_forNovember 7, 2023 · Neenu Chacko
- 03Rails 7.1 optimizes the default SQLite3 configurationOctober 31, 2023 · Vishnu M
- 04Rails 7.1 adds multi-column ordering to batch processingOctober 3, 2023 · Navaneeth D