Ruby uses the following characters #{} for string interpolation. If, for some reason, I would like to output those characters in a string, how would I do so?
Just use single quote:
puts '#{}'
Or if you want to use double quote, then escape it.
puts "\#{some_var} will be #{some_var}"
Single quotation will of course work, but what if you want to include them in string too and don't want to escape anything inside it? Use custom delimiter like that:
2.0.0p353 :001 > %q['"#{foo}[f]] #or e.g. %q&'"#{foo}[f]&
=> "'\"\#{foo}[f]"
%q is the equivalent of single quotes and %Q is for double quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With