Here is some tips in how to use block from Ruby best practices, I’ll try to add some of my code demo later on.
• If you create a collection class that you need to traverse, build on top of Enumerable rather than reinventing the wheel.
• If you have shared code that differs only in the middle, create a helper method that yields a block in between the pre/postprocessing code to avoid duplication of effort.
• If you use the &block syntax, you can capture the code block provided to a method inside a variable. You can then store this and use it later, which is very useful for creating dynamic callbacks.
• Using a combination of &block and instance_eval, you can execute blocks within the context of arbitrary objects, which opens up a lot of doors for highly customized interfaces.
• The return value of yield (and block.call) is the same as the return value of the provided block.