#{ } 在 Ruby 中的含义? [英] Meaning of #{ } in 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.
- http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#string
- http://www.ruby-doc.org/docs/编程Ruby/html/language.html
- http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/文字#Interpolation
- Ruby (on Rails) 语法
这篇关于#{ } 在 Ruby 中的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!