I’m trying to retrieve some ruby code from a database as a string, I
would then like to execute this code. So far I’ve tried many approaches
but my latest uses define_method.
I have a method defined to use define_method, i.e.
def define_validation_method(name, &block) self.class.send(:define_method, name, &block) end
What I would like to do is pass the code that I want executed to this
method as an example:
function_module = define_validation_method(
“do |x, y, z|
if x > 1
x = y + z
x = y - z
This of course does not work as the method expects a block not a string.
Can anyone suggest how to get this method to work, or suggest another
method. The code is being executed within a ruby class.