I need to be able to pass the variable name into an expression (in a cucumber) and want to be able to convert this string to a link (i.e. not a copy) of the variable.
eg.
Given /^I have set an initial value to @my_var$/ do
@my_var = 10
end
Then /^I update "([^"]*)"$/ do |var_name_string|
# I know I can get the value of @my_var by doing:
eval "@my_var_copy = @
eval "@#{var_name_string} = @my_var_copy"
end
Since Ruby is such a reflective language, I'm sure I'm trying to do it, but I haven't cracked it yet.
source
share