String interpolation single quote


#1

Hi,

I am trying to use string interpolation within single quotes instead of double ones, but the problem is it doesn't work.

for example:

user_input = 'test'
puts '#{user_input}'

The output is:

#{user_input}

My question is why does this not work? I also tried to replace the # with % and no success, that was recommend on Stackoverflow

I hope you guys can give me clear explanation about this.

Greetings,
Bithons


#2

As far as I know, single quote strings are meant to prevent any string interpolation or any operation inside the string, if you want to use these operations, you need the double quotes. But I didn't do a deep research on the subject, I could be wrong. Note that there are similar behaviours in some shells, that's why I'm not really surprised by this.