[ruby-core:96150] [Ruby master Feature#16379] Backporting ... to Ruby 2.4 - 2.6 and pass_keywords

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83020.20191209065529.bfa34fda7064a485@ruby-lang.org>
Issue #16379 has been updated by matz (Yukihiro Matsumoto).


As a general principle, I agree with Jeremy. But for this case only, @Eregon's "90% compatibility" sounds too tempting.
When we need to ask upgrading Ruby versions, it's far easier for users to upgrade within 2.5 or 2.6 than to 2.7 (or 3.0).

I am not going to rename `ruby2_keywords' to `pass_keywords`. It **is** ugly, but it should be disappeared after 2.6 EOL. So it's intentional.

Matz.

----------------------------------------
Feature #16379: Backporting ... to Ruby 2.4 - 2.6 and pass_keywords
https://bugs.ruby-lang.org/issues/16379#change-83020

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I've heard quite a few people saying that backporting `...` to Ruby 2.4-2.6 would be a good way to do migration for keyword arguments.
In fact, if we have `...` in Ruby 2.4+, I think `...` could be the way to do 90%+ of delegation in a backward-compatible way, and would be vastly more elegant than a hidden Hash flag (`ruby2_keywords`).

What does the Ruby core team think about that?

I think `...` works nicely for lexical delegation:
```ruby
def delegate(...)
  target(...)
end
```

It can also work for delegating in a separate method by using `...` inside a block inside the method accepting `...`:
https://eregon.me/blog/2019/11/10/the-delegation-challenge-of-ruby27.html#pass_keywords
```ruby
def initialize(...)
  @call_later = -> { target(...) }
end

def call
  @call_later.call
end
```

---

If we don't want to backport `...`, there is also the option to use `pass_keywords` like so:
```ruby
pass_keywords def delegate(*args, &block)
  target(*args, &block)
end
```

```ruby
pass_keywords def initialize(*args, &block)
  @call_later = -> { target(*args, &block) }
end

def call
  @call_later.call
end
```

Which can easily work by making `pass_keywords` a no-op on Ruby <= 2.6 and make `*args` behave like `...` on Ruby 2.7+.

---

I think both of these are easier to understand than `ruby2_keywords`, and both don't need to have any performance trade-off on unrelated code (#16188).

I'd like to have the opinion of the core team on this.
It has been suggested multiple times (notably in my blog post on 10 November), but I have not seen any opinion on this tracker about it.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.