How can I use a variable as a variable name in Ruby?
ruby, variables
Solution
You can make it work using eval:
eval "#{name}[0] = 1"
I strongly advise against that though. In most situations where you think you need to do something like that, you should probaby use a hashmap. Like:
context = { "video" => [] }
name = "video"
context[name][0] = 1
Problem
How can I make the code below work, so that both `puts` display `1`? ``` video = [] name = "video" name[0] = 1 puts name[0] #gives me 1 puts video[0] #gives me nil ```