Behaviour of different Proc types

I realized that I just can’t ever remember the different proc types
behaviours. So I wrote a script to check them.

My conclusion:
proc: Avoid this, since its behaviour differs across commonly used
implementations.
lambda: Use this if you want it to behave like a method.
Proc.new: Use this if you want it to behave like a block.

Is that reasonable? Any thoughts or insights? Do you have a different
set of
rules or a more elegant conclusion?

I realized that I just can’t ever remember the different proc types
[…]
Any thoughts or insights?

On a slightly related note:
http://innig.net/software/ruby/closures-in-ruby.rb

On Fri, 3 Jun 2011 13:22:18 +0900, Josh C. wrote:

Is that reasonable? Any thoughts or insights? Do you have a different
set of
rules or a more elegant conclusion?

I should note that proc behavior differs not across implementations,
but across
different Ruby [spec] versions, which are more of different languages
than just
versions.

I like Robert Sosinski’s explanation:
http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/

On Thu, Jun 2, 2011 at 11:22 PM, Josh C. [email protected]
wrote:

Is that reasonable? Any thoughts or insights? Do you have a different set
of rules or a more elegant conclusion?

I’ve added the note that -> is a synonym for lambda in 1.9.


Several people have posted links to articles, I appreciate that you are
interested enough to post these, but it’s unclear what you want me to
get
out of them, and they tend to be very long. It would help me, and
probably
other readers if you could summarize whether they agree with / disagree
with
/ expound on / or amend my conclusion, and maybe a sentence explaining
what
specifically we should should be paying attention to, if we invest the
hour
or so it would take to read the article.

I colorized Paul Cantrell’s exhaustive document =)

http://rubyprogrammer.net/~stu/closures-in-ruby.rb.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs