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

···

--
Anurag Priyam
http://about.me/yeban/

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.

···

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

I realized that I just can't ever remember the different proc types
behaviours. So I wrote a script to check them.
Analyzing the different behaviours of Ruby's Proc · GitHub

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?

--
   WBR, Peter Zotov.

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

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

···

On Thu, Jun 2, 2011 at 11:22 PM, Josh Cheek <josh.cheek@gmail.com> wrote:

I realized that I just can't ever remember the different proc types
behaviours. So I wrote a script to check them.
Analyzing the different behaviours of Ruby's Proc · GitHub

My conclusion:
  proc: Avoid this, since its behaviour differs across commonly used
[versions].
  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?

-----

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

···

On Fri, Jun 3, 2011 at 2:00 AM, Anurag Priyam <anurag08priyam@gmail.com> wrote:

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

--
Anurag Priyam
http://about.me/yeban/