Ruby Iterators

Watch out! This tutorial is over 4 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
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++.