Single quotation marks interpolation

How to interpolate in single quotes?

I tried something like this, but there are two problems.

string = 'text contains "#{search.query}"' 
  • Does not work
  • I need a final line for dynamic content enclosed in double quotes, for example:

     'text contains "candy"' 

It probably seems strange, but the gem I'm working with requires this.

+8
string ruby string-interpolation
source share
3 answers

You can use %{text contains "#{search.query}"} if you do not want to hide the double quotes "text contains \"#{search.query}\"" .

+11
source share
 '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'} 
+4
source share

Use

 %q(text contains "#{search.query}") 

which means the beginning of a line with a single quote. Or if you want to start by using a double quote:

 %Q(text contains '#{text}') 
-2
source share

All Articles