我正在使用 ruby 1.8.5,我想使用辅助方法来帮助过滤用户的偏好,如下所示:
def send_email(user, notification_method_name, *args)
# determine if the user wants this email
return if !user.send("wants_#{notification_method_name}?")
# different email methods have different argument lengths
Notification.send("deliver_#{notification_method_name}", user, *args)
end
这在 ruby 1.8.6 中有效,但是当我尝试在 1.8.5 中执行此操作并尝试发送多个 arg 时,我收到如下错误:
参数数量错误(X 为 2)
其中 X 是特定方法所需的参数数量。我宁愿不重写我所有的通知方法——Ruby 1.8.5 可以处理这个吗?