From: "David A. Black" Date: 2009-12-08T19:59:18+09:00 Subject: Re: convert string into a variable object HI -- On Tue, 8 Dec 2009, Steve Wilhelm wrote: > Toon Willems wrote: >> On 07 Dec 2009, at 21:35, Ad Ad wrote: >> >>>> to do. >>> >>> 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 > > Would it not be better to convert to symbols? That is: > > File.open(@file). each do |x| > @hash[x.strip.to_sym] = true > end > > if @hash[:toronto] > or > if @hash[:"palo alto"] > > or > > if @hash[city.to_sym] In addition to the garbage collection issue that David M. pointed out, symbols seem an odd choice to me for city names. I always think of symbols as appropriate for label-like functionality and values taken from a limited set. Strings are a better choice for general representation of text. David -- David A. Black Senior Developer, Cyrus Innovation Inc. THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally! January 22-23, Tampa, Florida Info and registration at http://www.thecompleatrubyist.com