From: snood1205@... Date: 2017-01-05T23:50:49+00:00 Subject: [ruby-core:78987] [Ruby trunk Feature#13108] [Doc Request] Explicitly document Range#sum Issue #13108 has been updated by Eli Sadoff. Subject changed from [Doc Request] Explicitly Range#sum to [Doc Request] Explicitly document Range#sum ---------------------------------------- Feature #13108: [Doc Request] Explicitly document Range#sum https://bugs.ruby-lang.org/issues/13108#change-62400 * Author: Eli Sadoff * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- While `Range#sum` exists because it implements `Enumerable#sum`, it is not noted how it works. While it does provide a hint that it is not an alias to `inject(:+)`, it is not explained that `(a..b).sum` implements `(b-a+1)*(a+b)/2` which is `O((log n)^2)` instead of `(a..b).inject(:+)` which is `O(n log n)`. It might be worth while either explicitly document `Range#sum` or at least documenting in `Enumerable#sum` that `Range#sum` has this behavior because the current documentation is not particularly descriptive and hides, what I think of, as quite a brilliant feature of 2.4.0. -- https://bugs.ruby-lang.org/ Unsubscribe: