简体   繁体   English

单引号内插值

[英]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. 可能看起来很奇怪,但是我正在使用的宝石需要此功能。

如果您不想转义双引号"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}')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM