[#122258] [Ruby Misc#21367] Remove link to ruby-doc.org from www.ruby-lang.org/en/documentation/ — "p8 (Petrik de Heus) via ruby-core" <ruby-core@...>
Issue #21367 has been reported by p8 (Petrik de Heus).
11 messages
2025/05/23
[ruby-core:121898] [Ruby Feature#20405] Inline comments
From:
"make_now_just (Hiroya Fujinami) via ruby-core" <ruby-core@...>
Date:
2025-05-08 04:37:52 UTC
List:
ruby-core #121898
Issue #20405 has been updated by make_now_just (Hiroya Fujinami).
Using type checkers makes it difficult to write Ruby fluently. To make type checkers work effectively in Ruby, we need to add numerous annotations, and these annotations are done via comments. However, Ruby only has line comments. This restricts our ability to annotate specific parts of an expression or pinpoint locations within a line; we cannot, for instance, comment directly on an individual argument within a method's parameter list on the same line or a portion of a complex expression.
A prime example of this is type casting. To cast a specific argument of a method, we often have to resort to workarounds like inserting a line break in the middle of the argument list or adding variables solely for the type checker. In other words, we are forced to write clumsy Ruby code.
(In the following example, a pair of `{=` and `=}` is used for syntax of inline comments.)
```ruby
# Before:
some_method(
foo,
[], #: Array[Integer]
bar
)
# or
tmp_var_for_type_check = [] #: Array[Integer]
some_method(foo, tmp_var_for_type_check, bar)
# After:
some_method(foo, [] {= as Array[Integer] =}, bar)
# or
some_method(foo, [] {= of Integer =}, bar)
```
Personally, I find this unenjoyable and feel it detracts from the "Rubyishness" of the language. Therefore, I believe that introducing inline comments is necessary to improve this situation.
Introducing inline comments also brings the advantage of enabling previously impossible annotations. These capabilities would further enrich Ruby's expressiveness.
```ruby
# Passing generic type parameters at the appropriate location
some_generics_method{= [Int, String] =}(foo, bar)
# Locally disabling code coverage
foo = cond ? 1 : {= :nocov: =} 2
# Commenting within percent literals
%w(
foo bar #{= comment =}
baz #{= comment =}
)
```
----------------------------------------
Feature #20405: Inline comments
https://bugs.ruby-lang.org/issues/20405#change-112967
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
----------------------------------------
I propose a new inline comment syntax.
```ruby
p (| This is a comment (| and nested one |) /:|) (:|) #=> :|
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/