gpt4 book ai didi

ruby - 用 ruby​​ 注释一行的一部分

转载 作者:数据小太阳 更新时间:2023-10-29 08:00:39 25 4
gpt4 key购买 nike

在 ruby​​ 中,你可以像这样在行尾添加注释:

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

或者像这样的多行:

=begin
Multi
lines
comment
=end

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

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

它存在于 ruby​​ 中吗?如果不是,为什么?

最佳答案

How come I can't find any ...?

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

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

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

关于ruby - 用 ruby​​ 注释一行的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com