From: knohr Date: 2007-06-14T06:50:09+09:00 Subject: Re: question: referencing a variable with a variable On Jun 13, 2:26 pm, knohr wrote: > I come from a perl background. I have gotten in the habit of using > references to variables instead of specifically calling said variable/ > class/whatever. > > Basically, I am wondering how I would translate the following into > ruby. > > example 1: > sub my_sub > { > $choice = shift; > $choices="this|that|foo|bar"; > if ( $choice =~ m/($choices)/ ) {&$choice} > else {die "some witty msg"} > } > > example 2: > > $this = 'var_name'; > $var_name = 'i want this to print'; > print $$var_name . "\n"; > > thanks s/print $$var_name/print $$this/