我有这个用于配置邮件 gem 的块。
Mail.defaults do
retriever_method :imap, :address => @mail_settings[:address],
:port => @mail_settings[:port],
:user_name => @mail_settings[:username],
:password => @mail_settings[:password],
:enable_ssl => @mail_settings[:enable_ssl]
end
@mail_settings 是可访问的,可以在 do 块之外读取,但不能在内部读取。我对红宝石很陌生,所以我试图理解为什么。现在,我收到了这个错误(第 66 行是retriever_method 行):
main.rb:66:in `block in set_mail_defaults': undefined method `[]' for nil:NilClass (NoMethodError)
奇怪的是,这有效:
address = @mail_settings[:address]
port = @mail_settings[:port]
user_name = @mail_settings[:username]
password = @mail_settings[:password]
enable_ssl = @mail_settings[:enable_ssl]
Mail.defaults do
retriever_method :imap, :address => address,
:port => port,
:user_name => user_name,
:password => password,
:enable_ssl => enable_ssl
end