3 ms·
I would have gone with "sane defaults": def publish!(time=Time.now) self.update published_at: time end keeps the simple case simple (self.publ
by masklinn 14y ago
I would have gone with "sane defaults":
def publish!(time=Time.now)
self.update published_at: time
end
keeps the simple case simple (self.publish!) but allows injection if needed (custom publication time or testing stub).
My language of choice being Python, I tend to do that rather often for injecting "classes" which will have to be instantiated: the function or object constructors takes callables (since Python's instantiation is just calling) with defaults provided.