Backslash breaks string interpolation in ruby -


i'd end string "/a_setting/c\blah = something" attribute gets evaluated value: blah. however, i'm seeing following behavior preceding backslash seems stop evaluation of variable:

attribute = "blah"
"/a_setting/c\#{attribute} = something"
=> "/a_setting/c\#{attribute} = something"
"/a_setting/c\ #{attribute} = something"
=> "/a_setting/c blah = something"

to string want:

"/a_setting/c\\#{attribute} = something" 

you need escape backslash backslash.

  • when "\#", "#" escaped, , interpreted not interpolation element, verbatim "#", in inspection, appears "\#" in front of {...} avoid ambiguity interpolation.
  • when "\ ", " " (redundantly) escaped, , interpreted verbatim " ".

Comments