[#111472] [Ruby master Bug#19274] Error installing ruby 3.2.0 on RH 8 — "aalllop (Alberto Allegue) via ruby-core" <ruby-core@...>
Issue #19274 has been reported by aalllop (Alberto Allegue).
5 messages
2022/12/28
[#111508] Data support for versions before 3.2.0 — Eustáquio Rangel via ruby-core <ruby-core@...>
I was wondering that every piece of code (gems, etc) that use the new Data =
3 messages
2022/12/29
[ruby-core:111122] [Ruby master Feature#19107] Allow trailing comma in method signature
From:
"byroot (Jean Boussier)" <noreply@...>
Date:
2022-12-01 08:51:16 UTC
List:
ruby-core #111122
Issue #19107 has been updated by byroot (Jean Boussier).
> Is there an actual case where this proposal is convenient?
Yes, when replacing old APIs that took an "option hash" by explicit keyword arguments, it tend to create very large signature.
The last example I have in mind is `redis-client`: https://github.com/redis-rb/redis-client/blob/dcfe43abb83597bee129537464e20805658bf7a9/lib/redis_client/config.rb#L21-L41
```ruby
def initialize(
username: nil,
password: nil,
db: nil,
id: nil,
timeout: DEFAULT_TIMEOUT,
read_timeout: timeout,
write_timeout: timeout,
connect_timeout: timeout,
ssl: nil,
custom: {},
ssl_params: nil,
driver: nil,
protocol: 3,
client_implementation: RedisClient,
command_builder: CommandBuilder,
inherit_socket: false,
reconnect_attempts: false,
middlewares: false,
circuit_breaker: nil
)
```
When adding a new argument, it cause these annoying diffs:
```diff
diff --git a/lib/redis_client/config.rb b/lib/redis_client/config.rb
index fc74367..6412171 100644
--- a/lib/redis_client/config.rb
+++ b/lib/redis_client/config.rb
@@ -36,7 +36,8 @@ class RedisClient
command_builder: CommandBuilder,
inherit_socket: false,
reconnect_attempts: false,
- middlewares: false
+ middlewares: false,
+ circuit_breaker: nil
)
@username = username
@password = password
```
Also this inconsistency is the reason why some popular styleguides reverted back to not using trailing comma for multi-line enumerations:
- https://github.com/testdouble/standard/pull/453#issuecomment-1234208705
- https://github.com/fables-tales/rubyfmt/issues/154
----------------------------------------
Feature #19107: Allow trailing comma in method signature
https://bugs.ruby-lang.org/issues/19107#change-100396
* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
----------------------------------------
A popular style for multiline arrays, hashes or method calls, is to use trailing commas:
```ruby
array = [
1,
2,
3,
]
hash = {
foo: 1,
bar: 2,
baz: 3,
}
Some.method(
1,
2,
foo: 3,
)
```
The main reason to do this is to avoid unnecessary noise when adding one extra element:
```diff
diff --git a/foo.rb b/foo.rb
index b2689a7e4f..ddb7dc3552 100644
--- a/foo.rb
+++ b/foo.rb
@@ -1,4 +1,5 @@
Foo.bar(
foo: 1,
- bar: 2
+ bar: 2,
+ baz: 3
)
```
However, this pattern doesn't work with method declarations:
```ruby
def foo(bar:,) # syntax error, unexpected ')'
```
### Proposal
For consistency and convenience I propose to allow trailing commas in method declarations.
--
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/postorius/lists/ruby-core.ml.ruby-lang.org/