From: Brian Candler Date: 2007-06-05T04:55:57+09:00 Subject: Re: Help needed: Dynamically create a Proc from a String and evaluate it On Tue, Jun 05, 2007 at 04:18:58AM +0900, Axel Etzold wrote: > I need help in dynamically creating a Proc from a String like, say, > > a='f(x)=c*exp(x/k)', If you're passing in c and k each time, then b = eval("proc{|c,x,k| c*Math.exp(x/k) }") puts b.call(5.0, 2.0, 1.0) This means you only call eval once, to create the proc object, then you can call it as many times as you like. If c and k really are constants then you can substitute them in to the proc definition: c = 5 k = 2 a = eval("proc { |x| #{c}*Math.exp(x/#{k}) }") puts a.call(3) or you can use the closure property to bind the local variables directly: c = 5 k = 2 a = eval("proc { |x| c*Math.exp(x/k) }") puts a.call(3) Brian.