I have a variable id
and I want to use it as a key in a hash so that the value assigned to the variable is used as key of the hash.
For instance, if I have the variable id = 1
the desired resulting hash would be { 1: 'foo' }
.
I've tried creating the hash with,
{
id: 'foo'
}
But that doesn't work, instead resulting in a hash with the symbol :id
to 'foo'
.
I could have sworn I've done this before but I am completely drawing a blank.