Ruby: Proc.new { 'waffles' } vs. proc { 'waffles' }
Asked Answered
C

1

36

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?

Camphene answered 17/1, 2011 at 6:28 Comment(0)
C
53

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.

Cholecyst answered 17/1, 2011 at 6:33 Comment(2)
Glorious. I'm using 1.9, so in my case, there are no differences.Camphene
See also: books.google.ca/…Liatris

© 2022 - 2024 — McMap. All rights reserved.