From: dblack@... Date: 2006-09-11T02:51:59+09:00 Subject: Re: patching strings together to make a variable Hi -- On Mon, 11 Sep 2006, Mike Dvorkin wrote: > How about: > > puts "#{eval('$' + 'var' + (if $a == true then "iable" end))}" > # => pass If your if fails you end up adding nil to a string, which will give you an error. So..... puts eval('$' + 'var' + ($a ? "iable" : "")) or something. David > Mike Dvorkin > http://www.rubywizards.com > > > > On Sep 10, 2006, at 6:50 AM, Sy Ali wrote: > >> $a = true >> $var = "fail" >> $variable = "pass" >> >> puts "#{$var(if $a == true then "iable" end)}" >> >> since $a == true, I would like this to become: >> puts "#{$variable}" > > -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org