How can I perform interpolation within single quotes?
I tried something like this but there are two problems.
string = 'text contains "#{search.query}"'
I need the final string to have the dynamic content wrapped in double quotes like so:
'text contains "candy"'
Probably seems strange but the gem that I'm working with requires this.
如果您不想转义双引号"text contains \\"#{search.query}\\""
可以使用%{text contains "#{search.query}"}
。
'Hi, %{professor}, You have been invited for %{booking_type}. You may accept, reject or keep discussing more about this offer' % {professor: 'Mr. Ashaan', booking_type: 'Dinner'}
Use
%q(text contains "#{search.query}")
which means start the string with single quote. Or if you want to start with double quote use:
%Q(text contains '#{text}')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.