|
|
|
|
|
by Quarrelsome
5534 days ago
|
|
Would you care to elaborate a bit? It seems your argument is basically: "HA HA look at the static language developers, aren't they stupid! They need to accept some fundamental truths and find their freedom!". I'm interested in what you have to say but I'd like to actually hear some technical reasons to support your argument. |
|
What does all this mean? How do you get the current time in a testable manner in Ruby? Use Time.now. You don't implement patterns or change your code. You don't fear the evil static..because really, it isn't a static - we don't even call it a static. It's just another method on another class, which we can rewrite at runtime as need be.
How do you stub it? Well, using a mocking framework:
Time.stub!(:now).and_return(Time.local(2011, 5, 3, 0, 1, 22))
The mechanics of how this is internally done isn't too complicated once you know about Ruby's metaprogramming (which probably takes around the same amount of time as getting familiar with C# or Java's reflection capabilities).
I know, it's a simple example. But it's surprisingly common. And I find it a little ridiculous that to get the time, we need to start creating interfaces and injecting parameters. While C#'s lambda's largely solve this problem, move to something just slightly more complicated, and you're back at square one.
I dunno, not sure if that explained it without being condescending. I'm tired...that stub is actually returning a pretty accurate time for me.