I have a Ruby template engine that uses eval(code_string, binding, source_file)
and every time this is called Ruby must parse the code string and it is perhaps not as fast as it could be.
I'd like to find an alternative, such as converting code_string
into a method, e.g. method = eval("lambda { #{code_string} }")
, before executing it, theoretically eval(method, binding, source_file)
.
But the problem is, I need to provide a binding and a source file name (and possibly a line number). Basically, I want eval to be able to take a lambda as a first argument, but so far I can't find a way to do this.