【发布时间】:2015-06-26 03:32:54
【问题描述】:
下面的->运算符是什么?
scope :published, -> { where(published: true) }
scope 是一个方法,:published 是一个作为参数传递的符号,这让我相信-> { where(published: true) } 构成了下一个参数。由于> 字符的存在,-> 不是有效的方法名称。
【问题讨论】:
-
Google for ruby lambda 运算符
-
它被称为'lambda literal'或'stabby lambda'。这只是创建 lamda 的一种方式。