fjs6 fjs6 - 1 year ago 114
Ruby Question

Create a ruby Proc from a string

I want to define the block as a string, then create the lambda.
The following example does not work.
Is something like this possible?

code_string = "|x|x*2"

l = lambda {eval(code_string)} => 6

Answer Source

This works

eval  "lambda { " + code_string + " }"

I just don't know why this one does and the other does not.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download