From: "Brian Schröder" Date: 2005-05-12T23:38:13+09:00 Subject: Re: Running a String as Ruby Code at Run-Time? On 12/05/05, speechexpert 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(/\/)" #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/