Spec-Zone.ru › Ruby 3

класс StopIteration

Родитель:
IndexError

Вызывается для остановки итерации, в частности методом Enumerator#next. Обрабатывается методом Kernel#loop.

loop do
  puts "Hello"
  raise StopIteration
  puts "World"
end
puts "Done!"

возвращает:

Hello
Done!

Публичные методы экземпляров

result → значение Показать исходный код
static VALUE
stop_result(VALUE self)
{
    return rb_attr_get(self, id_result);
}

Возвращает возвращаемое значение итератора.

o = Object.new
def o.each
  yield 1
  yield 2
  yield 3
  100
end

e = o.to_enum

puts e.next                   #=> 1
puts e.next                   #=> 2
puts e.next                   #=> 3

begin
  e.next
rescue StopIteration => ex
  puts ex.result              #=> 100
end

Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API