Actions
Bug #13222
closedArray#sum inconsistency when init value is non-numeric
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-02-17 trunk 57644) [x86_64-darwin15]
Description
Since Array#sum skips calling plus for 0
https://github.com/ruby/ruby/blob/c85a58d/array.c#L5831-L5832, it doesn't raise when the receiver array consists of 0 only, even when the "init" value is non-numeric.
% ruby -e "p [1].sum('a')"
-e:1:in `sum': String can't be coerced into Integer (TypeError)
% ruby -e "p [0].sum('a')"
"a"
% ruby -e "p [0, 0, 0].sum('a')"
"a"
Actions
Like0
Like0Like0Like0Like0