Very nice! If I understand correctly, I could do something like this:
def inject_constant(constant, value)
old_value = const_get(constant)
Then in a test, I could do this:
If all of my code is in the module MyApp, then all of my code uses
MockTime whenever it refers to Time. Forever in this case, which might
be fine in a test. Or I could pass a block to limit the duration. Or
use setup / teardown. If I want to be more fine grained I can just
inject into one class.
In any case, I can mock out the current time without messing up external
code, and without changing my original code. All without a fancy DI or
AOP framework. Wow!
Is this the cleanest implementation of this technique?
I went through all your DI presentation slides. Looks like it was a