Ruby: Proc.new { 'waffles' } vs. proc { 'waffles' }
-
11-10-2019 - |
Pergunta
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?
Solução
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.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow