Ruby’s blocks are one of the language features I like the most. The make iterating on collections extremely easy.
You can shorten the (already short!) syntax above, like so:
The above is implicitly calling
to_proc on the symbol. This es extremely handy, when you are calling the same method
on each object. However, it can also be useful to call a method with each object as an argument:
1 2 3 4 5 6 7
In addition, note that the number of arguments yielded to the method, depends on what the original implementation is. For hashes, this is especially useful:
1 2 3 4 5 6 7 8 9 10 11