Thanks all! Lots of good ideas!

-ke


-----Original Message-----
From: Tom Sawyer [mailto:transami / transami.net]
Sent: Thursday, July 18, 2002 5:05 AM
To: ruby-talk / ruby-lang.org
Subject: Re: How to name a variable after another variable's value?


try something like:

  greeting_no = "2"
  attr "sp#{greeting_no}_greeting".intern

and then you can do:

  send("sp#{greeting_no}_greeting=",'Hello')

~transami


On Thu, 2002-07-18 at 00:37, Kurt Euler wrote:
> All-
> 
> Is there a way to name a variable partly after the value of some other variable:
> 
> I tried to do something like this:
> 
> 	greeting_no = "2"
> 	sp#{greeting_no}_greeting = 'Hello'
> 
> ...with the idea of making 2nd line equivalent to writing:
> 
> 	sp2_greeting = "Hello"
> 
> ...but this didn't work.
> 
> Thanks!
> 
> -Kurt
> 
-- 
~transami

  _(")_  dobee dobee do...
   \v/  
   ^ ^