Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 IRB 控制台输出。
1.9.3p385 :005 > "Hello #{#'world'}" 1.9.3p385 :006 >
这不应该返回Hello吗?这是怎么回事?这是一个错误吗?
Hello
您需要删除第二个"#"字符。这使该行的其余部分成为评论。因此,它不是一条完整的线路。
"#"
"Hello #{'world'}"
正如 rjenkins 所说,“因此它不是一条完整的线路。”
为了证明这一点,并在 ERB 中完成该行,请执行以下操作:
键入"Hello #{#'world'}",然后按 Enter。然后键入}"并按 Enter。一旦你“完成了这条线”,你就会看到会发生什么。
"Hello #{#'world'}"
}"