Creating Proc from String?

I’m looking at extending a program that I’ve written to allow
arbitrary Ruby to be executed from within it. Basically, the
arbitrary Ruby will be executed ONLY in the context of something
like:

a = IO.readlines(current_file)
a.each custom_block

custom_block will be built from a string:

{ |line|

}

How would I do this? If I can get this figured out, then I’ll worry
about how I get it working under exerb later (:

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.11 at 15.16.22

Austin Ziegler wrote:

I’m looking at extending a program that I’ve written to allow
arbitrary Ruby to be executed from within it. Basically, the
arbitrary Ruby will be executed ONLY in the context of something
like:

a = IO.readlines(current_file)
a.each custom_block

custom_block will be built from a string:

{ |line|

}

How would I do this? If I can get this figured out, then I’ll worry
about how I get it working under exerb later (:

Something like this maybe?

irb(main):002:0> s = “x + 1”
“x + 1”
irb(main):003:0> pr = eval “proc {|x| #{s} }”
#Proc:0x401f1758@:1(eval)
irb(main):004:0> pr[3]
4