How can I change the comment symbol in Ruby? It is normally #
, but I want it to be a different character.
Asked
Active
Viewed 93 times
-1

sawa
- 165,429
- 45
- 277
- 381

GluecklichesHuhn
- 331
- 1
- 3
- 3
-
See also http://stackoverflow.com/questions/2989762/multi-line-comments-in-ruby?rq=1 for alternative versions of comments in ruby. – knut Apr 23 '16 at 16:40
2 Answers
5
You could modify the parser definition in the source code, compile it and run with your custom Ruby binary, modifying any gems you want to use to match your new comment scheme.
You could write some type of preprocessor script to modify your comments in rb
files to temporary files then launch ruby on those processed files.
Or you could deal with using #
.

Matt
- 68,711
- 7
- 155
- 158
1
- Propose your language change on the Ruby bug tracker, including:
- Present a really strong use case, why you want to break 10s of millions of lines of existing code written by 10s of thousands of developers.
- Create a proof-of-concept implementation for YARV, and ideally for the other implementations as well.
- (Ideally) Create an automated migration tool.
- Gather community consensus and support, respond to all questions and doubts.
- Iff your proposal gets accepted, there needs to be a transition plan. It will probably look something like this:
- When Ruby 2.4/3.0 gets released in December 2016, a deprecation notice will be added to the documentation.
- When Ruby 2.5/3.1/4.0 gets released in December 2017, a warning will be added about the upcoming deprecation of
#
. - When Ruby 2.6/3.2/4.1/5.0 gets released in December 2018, a switch will be added that allows you to choose between
#
and your proposal, with the default being#
. - When Ruby 2.7/3.3/4.2/5.1/6.0 gets released in December 2019, the default for the switch will be reversed.
- When Ruby 2.8/3.4/4.3/5.2/6.1/7.0 gets released in December 2020, the switch will be removed, and your proposal will be the new comment character for Ruby.
- Adoption of that version will probably be very slow, because of the massive backwards incompatibility your proposal induces, similar to Ruby 1.9 which took years to get adopted.
So, it's a lot of work for you, but sometime in 2021–2022, the Ruby community will have changed over to your proposal.

Jörg W Mittag
- 363,080
- 75
- 446
- 653
-
I forgot to add submit a bug to my list! =) Wouldn't 2.x and 3.x and 4.x stay with `#` now that they are semi semver? – Matt Apr 23 '16 at 10:41