#{ } 在 Ruby 中的含义? [英] Meaning of #{ } in Ruby?

查看:52
本文介绍了#{ } 在 Ruby 中的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作 #{ } 看起来非常基本,以至于我的 Ruby 书完全跳过了它的定义.有人能解释一下吗?

The operation #{ } appears to be so fundamental that my Ruby book completely skips its definition. Can someone provide an explanation?

推荐答案

为什么这是个好问题

除非您知道正确的搜索词,否则这对 Google 来说是一个棘手的问题.#{} 运算符在技术上执行字符串文字内的表达式替换.

Why This Is a Good Question

This is a tough question to Google for unless you know the right search terms. The #{} operator technically performs expression substitution inside a string literal.

#{} 文字是用于双引号字符串内插值的运算符,与反引号或 $() 相同构造将在 Bash 中使用.从实际的角度来看,对字面量内部的表达式求值,然后将整个#{} 表达式(包括运算符和它包含的表达式)替换原位em> 结果.

The #{} literal is the operator used for interpolation inside double-quoted strings the same way that the backticks or $() construct would be used in Bash. From a practical point of view, the expression inside the literal is evaluated, and then the entire #{} expression (including both the operator and the expression it contains) is replaced in situ with the result.

这篇关于#{ } 在 Ruby 中的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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