我在想,我怎么能重构这个代码,因为它没有看起来不错的阅读和理解重构轨方法
def next_payment_price
price = self.plan_price
price = discounted_price if self.coupon && self.coupon_duration.nil? && self.coupon_discount != 100
price = discounted_price if self.coupon && self.coupon_duration.present? && self.coupon_discount != 100 && ((self.created_at + 14.days + self.coupon_duration.month) > Time.now)
price
end
def discounted_price
self.plan_price - ((self.plan_price * self.coupon_discount)/100)
end
提取这优惠券类 – apneadiving
无法实现,因为优惠券是可以改变的,而在这个类中,我有静态数据,这将用于计算 –
是的...但是你可以用你的细节初始化一个优惠券对象,提醒:解耦你的lpgic,用它们创建对象自己的责任。 (基本上,人们鼓励你保持模型中的逻辑不要遵守这些准则) – apneadiving