If you can use an instance variable instead, there is Object#instance_variable_set .
def baz(symbol) instance_variable_set("@#{symbol}_bar", 42) end
Note that it only accepts variable names that can be accepted as an instance variable (starting with @ ). If you put anything else in the first argument, it will return an error. For a global variable similar to this, here is discussed: Forum: Ruby
In any case, you also have a problem with accessing the variable. How are you going to do this?
source share