From: "kyanagi (Kouhei Yanagita)" Date: 2022-01-28T23:13:45+00:00 Subject: [ruby-core:107330] [Ruby master Feature#18551] Make Range#reverse_each to raise an exception if endless Issue #18551 has been updated by kyanagi (Kouhei Yanagita). Eregon (Benoit Daloze) wrote in #note-1: > OTOH Range operations that work differently for numerics tend to make Range even more messy when it comes to non-numeric values (more differences in behavior, can't `reverse_each` efficiently on Date/Time/etc). I posted another ticket for performance issue: #18515 I wrote my thoughts there. ---------------------------------------- Feature #18551: Make Range#reverse_each to raise an exception if endless https://bugs.ruby-lang.org/issues/18551#change-96228 * Author: kyanagi (Kouhei Yanagita) * Status: Open * Priority: Normal ---------------------------------------- https://github.com/ruby/ruby/pull/5498 Currently, `Range#reverse_each` for an endless range never returns. ``` % ruby -e '(1..).reverse_each { }' # never return ... ``` (This is because `Enumerable#reverse_each` tries `#to_a` and `#to_a` for an endless range comes into an infinite loop.) I think `Range#reverse_each` for an endless range should raise an exception, similar to `Range#each` for a beginless range. ``` % ruby -e '(..1).each { }' -e:1:in `each': can't iterate from NilClass (TypeError) from -e:1:in `
' ``` -- https://bugs.ruby-lang.org/ Unsubscribe: