A Lambda Camcorder #
Beware magic-haters, a hack from Mike Williams, wherein you do a bunch of method calls on an anonymous object and the recording can get dup’d to lambda format.
people.select(&its.name.length > 10)
It’s the its method that’s the camcorder, creating a blank MessageBuffer to tape on to.
Ian
SQLBuilder in Ruby!
Ezra
ez-where is sql builder in ruby sort of ;)
flgr
Great name. I really like this. A lot. :)
<=>
This reminds me of some old Objective-C hacks which could be worth checking out, if you’re into that.
<=>
The idea there is more like people.whose.name.length > 10, though. I can’t decide which I like better.
n.n
... and of some new ones ( http://www.cocoade.com/developer.html )
MenTaLguY
v. awesome!
aberant
does this “it” camcorder do weddings?
binary42
My own try at implementing it:
Of course call can be added back to allow this sort of stuff:
The biggest plus is that it is already a Proc object, so we really don’t need any method visible… ruby will just use it as is. Something obscure like this now becomes possible:
The use of method_missing like this reminds me of >>= in Haskell… :-)
trans
Very cool. And yes, the names its is sweet.
This is very similar to facet/recorder too. I wonder if I can integrate this. Recorder is essentially a method probe. It records everthing that happens to it, building an internal parse tree. You can then pass a substitute object and apply the recoding to it. Or you can utilize the parse tree.
The only limitation of Recorder is with special operators, like if, &&, ||, etc. Since they are not true methods they can’t be recorded. (Too bad for Ruby.)
Simple Example:
produces true. Here’s the code:
Note that object_class == self.class.