Let's say I have an array of time lengths expressed in minutes:
minutes = [20, 30, 80]
I would like to sum the array contents and output the result in <hours>:<minutes>
format. For the example above I expect the result to be 02:10
.
Is there any standard Ruby method (i.e. included in core or std-lib) allowing to do this in an one line method chain? (i.e. without using a variable to store an intermediate result). I mean something like:
puts minutes.reduce(:+).foomethod { |e| sprintf('%02d:%02d', e / 60, e % 60) }
What should foomethod be? Object.tap is quite close to what I need, but unfortunately it returns self instead of the block result.