Issue #16253 has been updated by jeremyevans0 (Jeremy Evans).


ioquatix (Samuel Williams) wrote:
> Here are some real world examples from my code:
> 
> ```
> def self.for(*arguments, &block)
> 	self.new(block, *arguments)
> end
> 
> # Nicer?
> 
> def self.for(..., &block)
> 	self.new(block, ...)
> end
> ```

From reading the last dev meeting log (under `Future work: lead argument handling is postponed`), this will not be supported, at least initially.

> Module to be prepended:
> 
> ```
> module Connection
> 	def initialize(*)
> 		super
> 		
> 		# Other stuff
> 	end
> end
> 
> # Nicer?
> 
> module Connection
> 	def initialize(...)
> 		super(...)
> 		
> 		# Other stuff
> 	end
> end
> ```

I think a bare `super` makes more sense than `super(...)`, and it is backwards compatible.  However, in order to avoid keyword argument separation issues, if the super method accepts keyword arguments, you need to do `def initialize(*, **)` instead of `def initialize(*)` (`def initialize(...)` should also work).

> Many repeated code:
> 
> ```
> def self.split(*arguments, **options)
> 	append Split.new(*arguments, **options)
> end
> 
> # Nicer and more maintainable?
> 
> def self.split(...)
> 	append Split.new(...)
> end
> ```

Definitely looks nicer, so if you don't care about backwards compatibility, it seems like a good change.

----------------------------------------
Feature #16253: Shorthand "forward everything" syntax
https://bugs.ruby-lang.org/issues/16253#change-82181

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
What about using this:

```ruby
  def foo(*)
    @bar.foo(*)
```

to mean this:

```ruby
  def foo(*a, **o, &b)
    @bar.foo(*a, **o, &b)
```

I used `def foo(*)` because that's currently valid ruby code, but I'm fine with any syntax.

It's like the no-parentheses `super` shorthand, but for any method.

It makes it easier to write correct forwarding code. 

If rubyists must be told they have to change their forwarding code in 2.7 (due to keyword arguments), the pill might be easier to swallow if the change is a reduction rather than an increase in verbosity.

And we'd even be future-proof if an eventual FOURTH kind of parameter is introduced!!!!




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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>