On 07 Dec 2009, at 21:35, Ad Ad wrote: > 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/. > A much better way to do this would be to store the city names in a hash. your code would then be: File.open(@file). each do |x| @hash[x] = true end later on you can then just do if @hash[city] Toon