--001636ed68ac873eeb047a298c68
Content-Type: text/plain; charset=UTF-8

On Tue, Dec 8, 2009 at 3:35 AM, Ad Ad <codetest123 / gmail.com> 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"   #I need a logic for this
> end
>
> this would give us @toronto  , @miami  , 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/.
>
>
you can use

File.open("file").each{ |x|
instance_variable_set "@#{x}", 1
end

--001636ed68ac873eeb047a298c68--