Multi-Line Comments in Ruby?

2019-01-08 02:56发布

How can I comment multiple lines in Ruby?

标签: ruby comments
9条回答
Root(大扎)
2楼-- · 2019-01-08 03:22
=begin
My 
multiline
comment
here
=end
查看更多
太酷不给撩
3楼-- · 2019-01-08 03:28

Here is an example :

=begin 
print "Give me a number:"
number = gets.chomp.to_f

total = number * 10
puts  "The total value is : #{total}"

=end

Everything you place in between =begin and =end will be treated as a comment regardless of how many lines of code it contains between.

Note: Make sure there is no space between = and begin:

  • Correct: =begin
  • Wrong: = begin
查看更多
疯言疯语
4楼-- · 2019-01-08 03:31

Despite the existence of =begin and =end, the normal and a more correct way to comment is to use #'s on each line. If you read the source of any ruby library, you will see that this is the way multi-line comments are done in almost all cases.

查看更多
登录 后发表回答