Cole Mister wrote:
> The block is pretty much defining the yield statement?

In Ruby, code blocks are very important, but they're often a sticking 
point for newcomers (myself included) until you realise what they're 
doing.

Perhaps the easiest way to understand them is as anonymous subroutines. 
For example,

  { |f| puts f }

is something (but not exactly!) like:

  def nameless(f)
    puts f
  end

so anything you pass to nameless() gets printed. (Actually code blocks 
are much more than this, as they can carry around their local 
environment with them and be used as closures, but this should give you 
the general idea.)

You can now use iterators to do useful things like this:

  (1 .. 4).each { |f| puts f }

and 1, 2, 3, 4 will be fed in turn to the block. So the output will be

  1
  2
  3
  4

You can give a code block a life of its own, using lambda:

  x = lambda { |f| puts f }

and you can pass this Proc object x to methods, etc etc. Very useful 
once you get used to the idea.

Disclaimer: this is not the truth, the whole truth, and nothing but the 
truth, so please don't shoot me down in flames! "Education is a process 
of diminishing deception."

Dave
-- 
Posted via http://www.ruby-forum.com/.