Wednesday, August 20, 2008

Storing Procs In A Database

I started recently at ENTP.

The [hiring] decision was only reinforced when Giles sent me an email from a break between conference talks: “Why don’t you consider storing Ruby procs in the database?”.

In case anyone's wondering how you would accomplish this, it's actually easy, for certain procs. Somebody busted me once when I said it was totally easy - I think it was Ryan Davis - but I recovered from the bustedness because you kind of have to write the proc referring to variables outside the proc for it to be a real problem. So although there's a caveat it's a pretty avoidable caveat.

The method: You just store the procs as strings and eval the strings when retrieving them from the DB. I actually tested this in Rails for no very good reason once, and people have solved challenging problems in Lisp using a similar method.