Multi-Line Comments in Ruby?

后端 未结 10 1658
忘了有多久
忘了有多久 2020-11-30 16:21

How can I comment multiple lines in Ruby?

10条回答
  •  再見小時候
    2020-11-30 16:51

    #!/usr/bin/env ruby
    
    =begin
    Every body mentioned this way
    to have multiline comments.
    
    The =begin and =end must be at the beginning of the line or
    it will be a syntax error.
    =end
    
    puts "Hello world!"
    
    <<-DOC
    Also, you could create a docstring.
    which...
    DOC
    
    puts "Hello world!"
    
    "..is kinda ugly and creates
    a String instance, but I know one guy
    with a Smalltalk background, who
    does this."
    
    puts "Hello world!"
    
    ##
    # most
    # people
    # do
    # this
    
    
    __END__
    
    But all forgot there is another option.
    Only at the end of a file, of course.
    
    • This is how it looks (via screenshot) - otherwise it's hard to interpret how the above comments will look. Click to Zoom-in:

提交回复
热议问题