Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Proc.new { 'waffles' }在 Ruby 中,和之间有什么区别proc { 'waffles' }吗?我发现很少提及第二种语法。
Proc.new { 'waffles' }
proc { 'waffles' }
通过使用 进行测试irb,我没有发现任何明显的差异。第二个语法糖是第一个吗?
irb
来自 Metaprogamming Ruby 第 113 页。
在 Ruby 1.8 中,Kernel#proc() 实际上是 Kernel#lambda() 的同义词。由于程序员的强烈抗议,Ruby 1.9 将 proc() 改为 Proc.new() 的同义词。