This is usually a really difficult concept to grasp the first time.
You know how you can pass parameter objects to a method or constructor call in
Java?
Well in Ruby you can also pass a very special kind of object as a parameter called a
block or
closure. It doesn't look like a normal object, its simply a set of curly braces containing some code.
3.times{
// do something in this block
}
Here the times method is being called and is being passed a single block parameter (remember, the curly braces). It might be easier to visualize this if the syntax looked like:
3.times({ /* some code here */ })
because we're used to always seeing parameters
inside of paranthesis.