0
我正在尝试将用户输入à“6个月”转换成一个Ruby方法àla 6.months
。如何在没有接收器的情况下使用Ruby的send方法?
这怎么办?
我不断收到undefined method 6.months
错误行10
感谢您的帮助。
class Coupon < ActiveRecord::Base
def self.duration_options
["3 years", "2 years", "1 year", "6 months", "3 months", "1 month"]
end
def end_at
if Coupon.duration_options.include?(duration)
method = duration.sub!(' ', '.')
time = Time.zone.now + send(method)
end
time
end
end