Is is possible to create/use a regular expression pattern in ruby that is based on the value of a variable name?
For instance, we all know we can do the following wi
It works, but you need to use gsub! or assign the return to another variable
gsub!
var = "Value" str = "a test Value" str.gsub!( /#{var}/, 'foo' ) # Or this: new_str = str.gsub( /#{var}/, 'foo' ) puts str