6

Are there any multi line comments in Crystal ? Such as Ruby does :

=begin
    this is a
    multiline
    comment in Ruby
=end

This will simply give me an error in Crystal :

unexpected token: =

2 Answers2

6

Crystal doesn't have multi-line comments. Simply prefix the block of lines you want to comment out with # single-line comments. Your editor should be able to do this for you.

Stephie
  • 3,135
  • 17
  • 22
  • 2
    Seriously? No multi line comments? Doesn't sounds like something the creators would simply leave out... – Omer H Apr 09 '18 at 20:35
  • We left it out because all modern editors have a "comment block" feature to place a `#` at the start of the line—so just use that. Even vim has `:s/^/# /`, which operates on the selected block in visual line mode. – Stephie Apr 10 '18 at 00:33
  • Thanks, actually I do use Vim and the option for commenting out blocks is not that straightforward. Thanks for answering anyway, appreciated! – Omer H Apr 10 '18 at 11:23
  • 1
    @Stephie I think "=begin/=end" would still be useful, much faster than doing the `:s/^/# /,` trick in vim – Dorian Jun 05 '22 at 19:08
-1

Crystal allows multi-line comments by highlighting multiple lines and then using the shortcut Alt+M

  • 1
    That would be your IDE that does that, not the language. The IDE is the tool that allows you to edit the code in an efficient way, it is the IDE that has the shortcuts. The language does not possess any shortcuts itself unless you built a program that is reacting to them but the source code still would not. – Matthieu Raynaud de Fitte Jul 29 '22 at 23:22