我了解 proc 的概念,但有时我会看到这样的代码(取自 rails 验证指南http://guides.rubyonrails.org/active_record_validations_callbacks.html#using-if-and-unless-with-a-proc):
class Order < ActiveRecord::Base
before_save :normalize_card_number,
:if => Proc.new { |order| order.paid_with_card? }
end
似乎这可以更简单地写成:
class Order < ActiveRecord::Base
before_save :normalize_card_number, :if => :paid_with_card?
end
关于在这里使用 Proc 的优势,我没有得到什么?
提前谢谢