Blocks and yields in Ruby

Yes, it is a bit puzzling at first. In Ruby, methods can receive a code block in order to perform arbitrary segments of code. When a method expects a block, you can invoke it by calling the yield function. Example: Take Person, a class with a name attribute and a do_with_name method. When the method … Read more