davidhu2000 davidhu2000 - 4 months ago 12
Ruby Question

Is it possible to change ruby comment symbol?

So, to comment in ruby, you need the # symbol.

# this is some comments


Which is fine, but for multi-line comments, ruby has an ugly system.

=begin
comment line 1
comment line 2
=end


I have search around the internet and found nothing on the topic. I want to see if I am able to change that format to something better by defining my own commenting system. Such as:

/*
comment line 1
comment line 2
*/


I want to see if I can do something like

def /*
define comment logic
end
def */
define comment logic
end


Just something to that effect. I don't need to replace to current one, just want to see how I can define my own. I'm not looking to rewrite ruby. I just want to see if there is something simple that i can do whenever I write ruby. As an example, if I want to add a method to the String class, I can do

class String
def new_method
# some new functionality.
end
end


I want to see if I can do something like that for comments.

Answer

Nobody uses multi-line syntax. People do this instead:

# comment line 1
# comment line 2

Most editors have a shortcut that allows one to comment in multiple lines easily. You will get used to it!

Comments