Ruby:用于字符串插值和注释的语法(Ruby: syntax for string interpolation and commenting)
这个问题有很多类似的问题,但我认为没有人真的有我需要的答案。
根据我的理解,任何在其之前有#东西都会成为评论,如下所示:
puts "not a comment" # puts "in a comment"但是当涉及到字符串插值时,您可以说:
puts "time is #{Time.now}"并且#{Time.now}中的#{Time.now}不会开始评论它后面写的任何内容。
这是怎么回事?
There are a lot of similar questions to this one but i think none really had the answer i was in need of.
From what i perceived, anything that has a # preceding it becomes a comment, as in:
puts "not a comment" # puts "in a comment"but when it come to string interpolation, you can say:
puts "time is #{Time.now}"and the # at #{Time.now} doesn't start commenting whatever is written after it.
How is it so?
最满意答案
在这种情况下,#符号用引号括起来,并作为字符串的一部分进行分析,而不是作为注释。
The # sign in this case is encased in quotation marks, and is parsed as part of the string, not as a comment.
更多推荐
发布评论