From: "bughit (bug hit) via ruby-core" Date: 2024-05-30T16:31:52+00:00 Subject: [ruby-core:118105] [Ruby master Bug#20513] the feature of kwargs in index methods has been removed without due consideration of utility and compatibility Issue #20513 has been updated by bughit (bug hit). > Yes. The change is only for []=. Some methods like Dir[] do take keyword arguments, and it's unchanged. Someone should correct the release notes. This asymmetry/inconsistency between `[]` and `[]=` syntax is arguably even worse. Its arbitrary and incoherent. kwargs being legal in the index reader, strengthens the argument for them being legal in the index writer. @zverok I don't know why you're apologizing and retreating. First of all the release notes are wrong so its @jeremyevans0 who is out of line: > If you are going to complain about a change using a hypothetical, at least get the details correct, otherwise you appear not to know what you are talking about. How about those involved with this change "get the details correct" in the release notes first. Till then his "irritation" at any sown confusion is unjustified. Second. Your teaching scenario is still valid with a small adjustment. Try explaining to your hypothetical padawan why `IndexTest['foo', namespace: 'bar'] = 2` is illegal while `p IndexTest['foo', namespace: 'bar']` is legal. Its absurd. ---------------------------------------- Bug #20513: the feature of kwargs in index methods has been removed without due consideration of utility and compatibility https://bugs.ruby-lang.org/issues/20513#change-108538 * Author: bughit (bug hit) * Status: Closed * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- See #20218 The ability to pass kwargs to index methods has been in ruby for a long time, probably from the inception of kwargs, so there's code that makes use of it. Other than the multiple assignment edge-case it's been working fine and is not conceptually unsound. kwargs allow for more variability in store/lookup operations via index methods, letting you control where/how something is stored/looked up. this is from 2.6 ```ruby module IndexTest @store = {} def self.store @store end def self.key(name, namespace: nil) name = "#{namespace}:#{name}" if namespace name end def self.[](name, namespace: nil) p [name, namespace] @store[key(name, namespace: namespace)] end def self.[]=(name, opts = {}, val) p [name, opts, val] @store[key(name, namespace: opts[:namespace])] = val end end IndexTest['foo'] = 1 p IndexTest['foo'] IndexTest['foo', namespace: 'bar'] = 2 p IndexTest['foo', namespace: 'bar'] p IndexTest.store ``` A reasonable breaking change would be for `[]=` to have real kwargs, rather than the middle positional kwarg collector hash in the above example. I am not arguing that breaking changes can't be introduced, but that a removal of a long-standing feature deserves more consideration and deliberation than the following: > I found that use of keyword arguments in multiple assignment is broken > Can we also prohibit keyword arguments ... ? > OK, prohibit keyword arguments -- 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/