最近我在 Ruby on Rails http://railscasts.com/episodes/206-action-mailer-in-rails-3中看到一个很奇怪的代码
class UserMailer < ActionMailer::Base
default :from => "ryan@railscasts.com"
def registration_confirmation(user)
@user = user
attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
end
end
#controller
UserMailer.registration_confirmation(@user).deliver
这怎么可能?registration_confirmation
不是类方法(或有点像 C# 中的静态方法),它是一个实例方法!