单引号内插值 [英] Interpolation within single quotes

查看:48
本文介绍了单引号内插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单引号内执行插值?

How can I perform interpolation within single quotes?

我尝试过类似的方法,但有两个问题.

I tried something like this but there are two problems.

string = 'text contains "#{search.query}"'

  1. 它不起作用
  2. 我需要最后一个字符串来将动态内容用双引号括起来,如下所示:

  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"'

可能看起来很奇怪,但我正在使用的 gem 需要这个.

Probably seems strange but the gem that I'm working with requires this.

推荐答案

你可以使用 %{text contains "#{search.query}"} 如果你不想转义双引号 "文本包含 \"#{search.query}\"".

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

这篇关于单引号内插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆