I want to turn a string line
string = "variable.to_s"
You're capturing the wrong thing:
gsub! take a string or regular expression as the first argument and a string or block as the second argument. You're sending a regular expression to both.
If you need to use a portion of the match in the second part, capture it with brackets. You did this inadvertently in your code but on the wrong side.