参见英文答案 >
What is the -> (stab) operator in Ruby? 1个
> What does -> mean in Ruby 2个
我刚刚在Rails应用程序中遇到以下代码行:
> What does -> mean in Ruby 2个
我刚刚在Rails应用程序中遇到以下代码行:
scope :for_uid,->(external_id) { where(external_id: external_id) }
什么 – >操作符意味着这对谷歌来说很难.
解决方法
这是语法糖.
->(external_id) { where(external_id: external_id) }
等于:
lambda { |external_id| where(external_id: external_id) }