在验证中使用proc

Mel*_*lon 4 ruby-on-rails ruby-on-rails-3

在ruby on rails指南中,有一节5.3使用Proc:if和:除非讨论使用Proc:if和:除非在验证助手中.它给出了以下示例:

class Account < ActiveRecord::Base
  validates_confirmation_of :password,
    :unless => Proc.new { |a| a.password.blank? }
end
Run Code Online (Sandbox Code Playgroud)

Proc中的' a ' 是否指当前的Account实例?我能理解它('a')作为当前Account实例的参考吗?

:passworda.password指向同一个东西?

Ste*_*han 9

这正是它的本质.a指的是被验证的对象.