Describe a closure in Ruby

Technology CommunityCategory: RubyDescribe a closure in Ruby
VietMX Staff asked 3 years ago

closure is an object that is both an invocable function together with a variable binding. The object retains access to the local variables that were in scope at the time of the object definition.

A closure in Ruby retain variables by reference; the closure also extends the lifetimes of its variables. A closure’s reference to its variables is dynamically bound that means the values of the variables are resolved when the Proc object is executed.

It also possible to alter a closure. The binding of a closure can be altered using #binding.