In Files

  • enumerator.c

Parent

Methods

StopIteration

Raised to stop the iteration, in particular by Enumerator#next. It is rescued by Kernel#loop.

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

produces:

Hello
Done!

Public Instance Methods

result → value click to toggle source

Returns the return value of the iterator.

o = Object.new
def o.each
  yield 1
  yield 2
  yield 3
  100
end
e = o.to_enum
p e.next                   #=> 1
p e.next                   #=> 2
p e.next                   #=> 3
begin
  e.next
rescue StopIteration
  p $!.result              #=> 100
end
 
               static VALUE
stop_result(VALUE self)
{
    return rb_attr_get(self, rb_intern("result"));
}
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus