34

In Ruby, are there any differences between Proc.new { 'waffles' } and proc { 'waffles' }? I have found very few mentions of the second syntax.

From testing using irb, I haven't found any obvious differences. Is the second syntactic sugar for the first?

Andrew Grimm
  • 74,534
  • 52
  • 194
  • 322
ClosureCowboy
  • 19,889
  • 13
  • 56
  • 70

1 Answers1

51

From Metaprogamming Ruby Page 113.

In Ruby 1.8, Kernel#proc() is actually a synonym for Kernel#lambda(). Because of loud protest from programmers, Ruby 1.9 made proc() a synonym for Proc.new() instead.

Prajna
  • 1,197
  • 11
  • 10
  • Glorious. I'm using 1.9, so in my case, there are no differences. – ClosureCowboy Jan 17 '11 at 06:37
  • 1
    See also: http://books.google.ca/books?id=jcUbTcr5XWwC&pg=PA194&lpg=PA194&dq=ruby+proc+synonym&source=bl&ots=fHJltd8taE&sig=pHkE5W-c9iHHHHfacmuPzeYuI48&hl=en&ei=fuMzTanHDo2usAPyqLTgBQ&sa=X&oi=book_result&ct=result&resnum=6&ved=0CDUQ6AEwBQ#v=onepage&q=ruby%20proc%20synonym&f=false – Zabba Jan 17 '11 at 06:37