In Ruby 2.4 and for entire ranges Range(Enumerable)#sum optimized to return the result directly, without repeating all the elements.
I do not understand why the corresponding code is defined in enum.c for Enumerable , and not range.c for the Range class.
Why does Enumerable know about classes that include it (e.g. Range , Hash , ...) and check their type instead of letting these classes overwrite Enumerable#sum ?
In the enum.c field:
return int_range_sum(beg, end, excl, memo.v);
source share