Ruby:Proc.new {'waffles'} 与 proc {'waffles'} [英] Ruby: Proc.new { 'waffles' } vs. proc { 'waffles' }

查看:32
本文介绍了Ruby:Proc.new {'waffles'} 与 proc {'waffles'}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ruby 中,Proc.new { 'waffles' }proc { 'waffles' } 之间有什么区别吗?我发现很少有人提到第二种语法.

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

从使用 irb 进行的测试来看,我没有发现任何明显的差异.第二种语法糖是第一种吗?

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

推荐答案

来自 Metaprogamming Ruby 第 113 页.

From Metaprogamming Ruby Page 113.

在 Ruby 1.8 中,Kernel#proc() 实际上是 Kernel#lambda() 的同义词.由于程序员的强烈抗议,Ruby 1.9 将 proc() 改为 Proc.new() 的同义词.

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.

这篇关于Ruby:Proc.new {'waffles'} 与 proc {'waffles'}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆