From: Heesob Park Date: 2008-08-11T14:02:47+09:00 Subject: Re: Expanding variables in a string 2008/8/11 Thind, Aman : > Thanks for the reply! > > If I do eval(myaction) then it thinks all the words in the string are > variables and complains: > > irb(main):002:0> myaction = 'perl #{ENV[HOME_SCRIPTS]}/myscript.pl > -#{params[:date]}' > => "perl \#{ENV[HOME_SCRIPTS]}/myscript.pl -\#{params[:date]}" > > irb(main):004:0> eval myaction > NameError: undefined local variable or method `perl' for main:Object > > What I want is for all the known variables in the string to be expanded; > the same effect that assignment with double quotes has. > > Please remember I know using double quotes in the assignment to myaction > would solve the problem but I am doing this assignment only for > illustration. > > I actually get the string from a db query so have to expand the > variables after the assignment. > You could try something like this: myaction.gsub(/#\{(.+?)\}/){eval($1)} Regards, Park Heesob