A block is similar to a method, except it is not part of an object. Closures are the name given to blocks in different programming languages. There are a few key elements to remember regarding Ruby Blocks: Block is a function that takes arguments and returns a value. Block does not have a moniker of their own.
Scoping is lexical in Ruby. There can be several levels of scope and scope can even be altered. In Ruby, when a block is called, it is bound to the caller's scope. This means that variables defined above the block are available inside the block inside the same method.
Share a personalized message with your friends.