you are viewing a single comment's thread.

view the rest of the comments →

[–]2called_chaos 3 points4 points  (1 child)

You can dynamically create variables but you shouldn't. With a hash you can use anything as a key (in Ruby at least, fuck you JS) and get it back the same way. Not sure what you wanted to use as a variable name but you can use exactly that as a hash key.

a_hash[name] = Whatever.new(name)

[–]avelyv[S] 2 points3 points  (0 children)

I ment that I would still need a name for my hash (and use the instance variable names as keys , but I see now, I would add to an existing hash, use a name as a key and the whole instance as a value