Project

General

Profile

Actions

Bug #19426

closed

Endless `Range#step` of object with `#succ` method does not work

Added by nobu (Nobuyoshi Nakada) about 1 year ago. Updated about 1 year ago.

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

Description

Consider this c object which hash #succ method.

c = Struct.new(:i) do
  def succ; self.class.new(i+1); end
  def <=>(other) i <=> other.i;end
end.new(0)

This Range#step works.

(c..c.succ).step(1) do |d|
  p d.i # 0, 1
end

But it fails on an endless range.

(c..).step(1) do |d|
  p d.i
  break if d.i > 3
end
-:3:in `<=>': undefined method `i' for nil:NilClass (NoMethodError)
	from -:10:in `step'
	from -:10:in `<main>'
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0