In the context of the Ruby programming language, what is a closure and when do you use one? What are the uses for it in Rails?
Asked
Active
Viewed 7,815 times
1 Answers
7
Try this link: Understanding Ruby Closures. Another one: Understanding Ruby Blocks, Procs, and Lambdas. In a nutshell, a closure is a function plus a context in which the function is called. The context contains state information that the function can access, but which isn't part of the function itself. Ruby has several different kinds of closures: blocks, procs, and lambdas.
Also (from Michael): http://www.skorks.com/2010/05/closures-a-simple-explanation-using-ruby/
-
3This is little more than a link-only answer. – raptortech97 Dec 20 '14 at 02:52
-
1@raptortech97 It's actually "a little more" than a link only answer, where the "little more" is a concise explanation of what a closure is and how that relates to Ruby. – Caleb Dec 20 '14 at 22:08
-
[Understanding Ruby Blocks, Procs, and Lambdas](http://www.reactive.io/tips/2008/12/21/understanding-ruby-blocks-procs-and-lambdas) - link in post not working – notapatch Jul 17 '16 at 22:34