Ruby Iterators

Tutorial Difficulty Level    

Ruby iterators are methods which take and run a block of code. The block can be delimited by curly braces or by the keywords do and end. The brackets have higher precedence, and variables declared in them are destroyed when the bracked code exits.

The parameter names for the block are listed between | symbols at the start of the block. This syntax is borrowed from Smalltalk.

Note: Ruby uses the term “iterator” rather differently than C++.