Learn
Methods, Blocks, & Sorting
How Blocks Differ from Methods
There are some differences between blocks and methods, however.
Check out the code in the editor. The capitalize
method capitalizes a word, and we can continually invoke the capitalize
method by name. We can capitalize("matz")
, capitalize("eduardo")
, or any string we like to our hearts’ content.
However, the block that we define (following .each
) will only be called once, and in the context of the array that we are iterating over. It appears just long enough to do some work for each
, then vanishes into the night.
Instructions
Make sense? Run the code to see the magical marriage of methods and blocks.