From: zverok.offline@... Date: 2019-10-16T13:17:04+00:00 Subject: [ruby-core:95367] [Ruby master Feature#16253] Shorthand "forward everything" syntax Issue #16253 has been updated by zverok (Victor Shepelev). > But it's true that often we want to operate on the arguments before forwarding, so I think maybe an asymmetric syntax like this would work best? BTW, that's very valid point ��� similar problem was discussed here: https://bugs.ruby-lang.org/issues/15049#change-73845: There was a request for "all current method arguments list" API, and examples there were related to delegation, too. Quoting from there (my code example and comment) ```ruby def get(path:, accept: :json, headers: {}, **options) _request(method: :get, __all the rest of what have passed to this method___) end def post(path:, body:, accept: :json, headers: {}, **options) _request(method: :post, __all the rest of what have passed to this method___) end # ...and so on ``` > Two of currently available options: > 1. Accept just **arguments, and make checking what was mandatory, what should have default value and so on manually (also making auto-generated docs less expressive) > 2. Accept everything as in my example, and then just do `_request(method: :get, path: path, body: body, accept: accept, headers: headers, **options)` ...that looks not DRY at all. The solution proposed there was something like ```ruby def get(path:, accept: :json, headers: {}, **options) _request(method: :get, **kwargs) # pass ALL arguments end ``` ...but following your suggestiong, it could've been ```ruby def get(path:, accept: :json, headers: {}, **options) _request(method: :get, ***) # pass ALL arguments end ``` ...which is kinda nice. ---------------------------------------- Feature #16253: Shorthand "forward everything" syntax https://bugs.ruby-lang.org/issues/16253#change-82075 * 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: