Actions
Patch #44736
openUse Enumerable#sum instead of inject and explicit loops to calculate totals
Status:
New
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
Description
Some totals in Redmine are still calculated with inject(0) or an explicit loop. These were written before Enumerable#sum became available in Ruby 2.4:
TimelogHelper#sum_hoursRedmine::Helpers::TimeReport#run(@total_hours)Redmine::Helpers::Gantt#number_of_rows
The attached patch replaces them with Enumerable#sum, for example:
# Before
sum = 0
data.each do |row|
sum += row['hours'].to_f
end
sum
# After
data.sum {|row| row['hours'].to_f}
Enumerable#sum states the intent directly, which makes the code easier to read.
Files
No data to display
Actions