3 ms·
The tucking-away of current_date and current_day inside discount_day? is a mess. If either change between calls to discount_day?, suddenly discount_day? is retu
by damncabbage 15y ago
The tucking-away of current_date and current_day inside discount_day? is a mess. If either change between calls to discount_day?, suddenly discount_day? is returning the wrong value. That method returns different values given the same inputs; it's not a good candidate for being memoized.
(Furthermore, it's harder to test, as now current_date and current_day need to be stubbed out. It's also less obvious which day is being checked with regards to being discount day or not.)
I'd recommend having discount_day? taking a date as the argument, and having it invoked as discount_day?(current_date). (The day can then be calculated from the provided date.)