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:
class Z def name ; 'George' ; end def age ; 12 ; end end z = Z.new r = Recorder.new q = proc { |x| (x.name == 'George') & (x.age > 10) } x = q[r] x.__call__(z)produces true. Here’s the code:
class Recorder # Privatize all kernel methods. private *instance_methods def initialize( msg=nil ) @msg = msg end def inspect "<Recorder #{@msg.inspect}>" end def __call__( orig ) return orig unless @msg sym = @msg[0] args = @msg[1..-1].collect do |a| Recorder === a ? a.__call__(orig) : a end obj = args.shift obj.__send__( sym, *args ) end def method_missing( sym, *args, &blk ) object_class.new( [ sym, self, *args ] ) end endNote that object_class == self.class.