From: Gregory Millam Date: 2003-12-15T12:07:00+09:00 Subject: Re: Q: How to convert hashed parameters to local variables? Received: Mon, 15 Dec 2003 11:38:30 +0900 And lo David wrote: > > The variables you create that way will only be in scope in the > eval block itself: > > eval "a = 1; puts a" # 1 > puts a # error: a is undefined > > > David > Not quite; eval creates variables at current scope, But you are right about one thing - the .each |key,val| scope will keep all the variables. str = "" args.each do |key,val| str << "#{key}='#{val}'\n" end eval str # Will place all the variables at the current scope. I still recommend using the regexp search-and-replace instead of that, though. It also doesn't require the string itself to be in the templating function. Not to mention all the ickiness involved with eval, etc.