4

在 ruby​​ 中,您可以像这样注释行尾:

puts "This is a line" # Comment for end of line

或像这样的多行:

=begin
Multi
lines
comment
=end

为什么我找不到有关仅注释行的一部分的语法的任何信息,例如,在 C 中:

if (my_condition()/* || true */)

它存在于红宝石中吗?如果不是,为什么?

4

2 回答 2

4

我怎么找不到……?

因为没有。如果你想这样做,也许你可以这样做:

some_code.tap{%q{some comments blah blah blah}}.some_more_code_to_continue

尽管看起来不太好,但您可以理解.tap{%q{...}}为C 中的含义。/*...*/在某些语言中,人们确实设法使用现有语法制作内联注释;例如,在 TeX 中,\if\false...\fi经常使用。

于 2013-03-06T12:06:20.787 回答
0

没有您正在寻找的确切传递性,但您可以使用\nand轻松伪造它\

# Inserted `\ #`   ⇓⇓⇓ and CR ⇓⇓⇓  
if (my_condition() \ # || true 
)
于 2013-03-06T12:12:42.080 回答