Exception: StopIteration
- Inherits:
- 
      IndexError
      
        - Object
- Exception
- StandardError
- IndexError
- StopIteration
 
- Defined in:
- enumerator.c,
 enumerator.c
Overview
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!
Direct Known Subclasses
Instance Method Summary collapse
- 
  
    
      #result  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the return value of the iterator. 
Methods inherited from Exception
#==, #backtrace, #backtrace_locations, #cause, #detailed_message, #exception, exception, #full_message, #initialize, #inspect, #message, #set_backtrace, #to_s, to_tty?
Constructor Details
This class inherits a constructor from Exception
Instance Method Details
#result ⇒ Object
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
puts e.next                   #=> 1
puts e.next                   #=> 2
puts e.next                   #=> 3
begin
  e.next
rescue StopIteration => ex
  puts ex.result              #=> 100
end
| 2905 2906 2907 2908 2909 | # File 'enumerator.c', line 2905
static VALUE
stop_result(VALUE self)
{
    return rb_attr_get(self, id_result);
} |