An Inconvenient Bandwagon...
One of the directories we publish our offerings to has a CarbonImpact field in their web service API. (No, we don’t track that in our database.)
Look, I’m all in favor of greening up various industries; it’s needed to happen for quite some time. But stupid stuff like this is going to reduce the environmental movement to a fad, when it needs to be a sustained effort. Energy efficiency ratings need to be printed on labels for physical goods, not services.
Read more...Naughty, but I like it...
Normally you can’t add objects to an array like this:
irb(main):001:0> [1] + 1 TypeError: can't convert Fixnum into Array from (irb):1:in `+' from (irb):1
But Array#+ tries to call to_ary() on its target if it’s not already an array. So just add that method, and voila:
irb(main):002:0> class Fixnum; def to_ary; [self]; end; end => nil irb(main):003:0> [1] + 1 => [1, 1]
Wait, why stop there?
irb(main):005:0> class Object; def to_ary; [self]; end; end => nil irb(main):007:0> [1] + "foobar" + File.new('test.xml') => [1, "foobar", #<File:test.xml>]
Of course, you should probably be using Array#<< for this. But I wonder what other applications there are…
Read more...A time-sink is born...
Found an old e-mail to my brother that is basically the inception of Zyps. Not sure of the exact date, because dates got eaten by a corrupted mbox file eons ago. Whenever Wired profiled the MIT Ants project, I guess.
Read more...__pre_to_s, __post_to_s...
The design by contract bits in the Ruby Cookbook are interesting if only for the fact that they got me thinking about all the options for wrapping a method. By including a module in your class, you can set up code to run before or after a method call, for a specific method or all methods. That means you can check arguments, check output, or maybe even alter the input or output.
When flipping through the Module documentation this time, my only thought was, “Oh, neat, they have #included, #extended, and #method_added callbacks. Those might be useful someday.” Well, only now am I starting to see concrete uses, and they’re potentially so powerful it blows my mind.
My main remaining gripe is how sloppy aliasing methods is. I’d rather not have a bunch of __pre_x(), __post_x(), __original_x() methods lurking under the hood of my classes. But at least it’s becoming clear that I can hide this ugliness from myself.
Read more...Have you noticed what a central notion powerup management is to many games? D and I were playing Gauntlet last night, and we knew we’d barely squeak by the level we were on. So every hunk of cheese that dropped was carefully rationed to ensure it wasn’t wasted on a mostly-full health bar. This happened on the fly, but required a bit of hasty debate.
I don’t think this is even an intentional gameplay mechanic for most games that have it, but maximum HP definitely increases the need for teamwork. I wonder if the model can even be improved upon…
Read more...