$ 1 and $ 2 are not really related to your regular expression: method arguments are evaluated before the method is called, therefore
"#{$1} and #{$2}"
Evaluated before the regular expression matches your string. If you did not execute earlier regular expressions, then these variables will be equal to zero, therefore you actually execute
file = file.gsub(/(\b) \/ (\b)/, " and ")
that is, you replace the forward slash surrounded by spaces, the "and", also surrounded by spaces. $ 1 and $ 2 will be updated to be empty lines, and therefore you will see the same behavior when processing the next line.
source share