我看到不一致的行为,我想知道我在这里做错了什么。
我有subscription
个对象,其状态由其cycle
和con
属性定义,即整数。 months_passed
会返回一个整数,该整数计算订阅start_date
与Time.current
之间经过的完整月数。
def update_state
update_cycle
update_con
self.save
end
def update_cycle
self.cycle = if months_passed > 0
(months_passed - 1)/3 + 1
else
0
end
end
def update_con
self.con = if months_passed > 0
(months_passed - 1) % 3 + 1
else
0
end
end
def in_con1?
update_state
con == 1
end
然而,当我快速连续呼叫in_con1?
时,我会不一致地变得正确或错误。
我需要重新加载对象吗?是陈旧的吗?
答案 0 :(得分:0)
months_passed
被召唤的时候,就在我预料到的前一个小时。