Both lambda and proc work
as well, incidentally. Actually, from what I've read they're identical
in 1.8 (which is what I'm using), but not in 1.9,
Not exactly.
* lambda and Proc are different to each other in both ruby1.8 and ruby1.9.
Also, they are different in the same way
* in ruby1.8, proc {} is a synonym for lambda {}
* in ruby1.9, proc {} is a synonym for Proc.new {}
So to play it safe, never use proc {} - always use lambda {} or Proc.new {}
For a detailled discussion of the differences, see
http://innig.net/software/ruby/closures-in-ruby.rb
(although I disagree with his rant: these inconsistencies are carefully
considered to make Ruby "do the right thing" in various scenarios)
If you are using closures in the way discussed in this thread, then I think
lambda {} is probably the best choice as you get a true closure which is
fully independent of the thread of execution where it was defined.
Regards,
Brian.
Hi Brian --
Both lambda and proc work
as well, incidentally. Actually, from what I've read they're identical
in 1.8 (which is what I'm using), but not in 1.9,
Not exactly.
I think the statement as written is correct: lambda and proc are the
same in 1.8 (with Proc.new being different from both), but in 1.9,
lambda is one thing and proc/Proc.new are another (and the same as
each other).
* lambda and Proc are different to each other in both ruby1.8 and ruby1.9.
Also, they are different in the same way
* in ruby1.8, proc {} is a synonym for lambda {}
* in ruby1.9, proc {} is a synonym for Proc.new {}
So to play it safe, never use proc {} - always use lambda {} or Proc.new {}
The original plan, as of RubyConf 2004, was to deprecate proc
entirely. At least, I got Matz to say he would on that occasion I
rather wish that had happened. In any case, there's also ->(){} in 1.9
of course....
David
···
On Tue, 9 Sep 2008, Brian Candler wrote:
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!