Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolation within single quotes

How can I perform interpolation within single quotes?

I tried something like this but there are two problems.

string = 'text contains "#{search.query}"'
  1. It doesn't work
  2. 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.

like image 842
Dru Avatar asked Feb 16 '13 16:02

Dru


2 Answers

You can use %{text contains "#{search.query}"} if you don't want to escape the double quotes "text contains \"#{search.query}\"".

like image 185
nowk Avatar answered Nov 12 '22 02:11

nowk


'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'}
like image 32
Ahmed Eshaan Avatar answered Nov 12 '22 02:11

Ahmed Eshaan