Project

General

Profile

Actions

Feature #18551

closed

Make `Range#reverse_each` to raise an exception if endless

Added by kyanagi (Kouhei Yanagita) almost 3 years ago. Updated 12 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:107299]

Description

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 `<main>'
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0