Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.