There is a tendency among Ruby on Rails developers to specify time in constants. But this practice is quite dangerous and a bit obscure.
A classic example:
What do you expect to happen there the first time you run this code? And what will happen 10 minutes later?
In Rails the code will get loaded at the startup and executed every time it is needed, but a constant is a constant and it is not supposed to change (obviously). And if the constant will not change, 1.second.ago, after 10 minutes will be 10 minutes and 1 second ago; the same will happen after one month or two. And this is probably not the behaviour that the developer expected when assigning ‘1.second.ago’ to the constant ONE_SEC_AGO.
How to fix that?
Instead of using a constant, use a method (and private):
Or if you really wanna use a constant:
comments powered by Disqus