Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline comments in Ruby

Tags:

comments

ruby

Is Ruby able to understand in-line comments like:

my_array = ['first', /* 'second', */ 'third', 'fourth'] 

?

Update:

I asked not about what is /* */ in Ruby and why I receive an error, but about presence of in-line comments in any available form at all. /* */ were given only as example of in-line comments known to me.

like image 654
Paul Avatar asked Oct 29 '12 22:10

Paul


People also ask

How do you comment a line in Ruby?

Single-Line Comments The Ruby single-line comment begins with the # character and ends at the end of the line. Any characters from the # character to the end of the line are completely ignored by the Ruby interpreter.

What are inline comments?

Inline comments are comments made by an instructor that appear directly on top of your paper. These comments are usually brief.

What is magic comment in Ruby?

A magic comment changes the behavior of the Ruby interpreter in some way. For example: The frozen_string_literals comment will make your strings frozen by default. It looks like this: # frozen_string_literal: true. Another magic comment allows you to change the file's encoding.


1 Answers

No, Ruby does not have inline comments.

Comments of this style have a tendency to reduce readability, since they makes the code harder to follow.

In your case it would be best to split your array items into separate rows and comment out the one row.

my_array = ['first', #           'second',             'third',             'fourth'] 
like image 71
Douglas F Shearer Avatar answered Sep 22 '22 09:09

Douglas F Shearer