Ruby on Rails: Blocks and Closures
Based on an interview with Yukihiro Matsumoto, Ruby’s architect, a closure object has the executable, or the code to run, and the scope, which is the state around the code. When you capture the environment, namely the local variables, in the closure, you can refer to the local variables inside a closure as a result. Even after the function has returned, and its local scope has been destroyed, the local variables remain in existence as part of the closure object. When no one refers to the closure anymore, it is considered as garbage collected, and the local variables go away.
