From: Ad Ad Date: 2009-12-08T05:35:39+09:00 Subject: Re: convert string into a variable object Aldric Giacomoni wrote: > Ad Ad wrote: >> Hi, >> I have a string named "ruby". I want to create an empty object by that >> name: @ruby >> >> Is there a way to do this? > > Yes. > Also, it is most likely that there is an easier way to do what you want > to do. > What _do_ you want to do? I have a file with a list of cities in it. The file is a daily feed and the cities in it change daily. I want to create a class which reads the file and creates the variables with the city names. File.open("file").each{ |x| @"x" = 1 #I need a logic for this end this would give us @toronto = 1, @miami = 1, etc. I have subclasses which would read user input and if that city variable has been defined already then move ahead. it would be a simple if statement if @toronto ... end I could create a hash map too but this is the easiest way to do since it doesnt require the creation of any sort of a container variable. -- Posted via http://www.ruby-forum.com/.