read
Basically Enumerable mixin gives collection classes a variety of traverse, search, sort methods.
Understanding ruby blocks
Blocks are statements of code written in ruby. one can take them as similar to c language macro’s
Different ways to define blocks
Passing block to enumerator
Lets assume we have collection array of strings and we want to print it
Understanding symbol#to_proc
Symbol has method to_proc
which converts symbol to block where symbol is taken as method to be executed on first argument of proc
** How to_proc got implemented inside Symbol class**
Lets have some examples:
Is there any shortcut?
Yes, there is shortcut to have block passed to enumerators on the fly using ampersand followed by colon (i.e. symbol)
Some handy examples