On 12/05/05, speechexpert <speechexpert / sbcglobal.net> wrote:
> I want to set up a state machine, in this case I am parsing a simple
> scripting language using regexp, and then running
> a segment of code, which might be another regexp, etc. I'd like to be be
> able to specify that code in a file...
> 
> Can I feed a String like "str = a.scan(/\<cat.*?>/)"            #regexp here
> is just an example ;)
> into a method or any other way and have it execute?

Take a look at eval

irb(main):001:0> s = "1+10+13"
=> "1+10+13"
irb(main):002:0> eval s
=> 24
irb(main):003:0> eval 's.scan(/\\d+/)'
=> ["1", "10", "13"]

regards,

Brian
> 
> TIA
> John B
> 
> 


-- 
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/