ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:103305] [Ruby master Feature#17785] Allow named parameters to be keywords
@ 2021-04-08 15:08 marcandre-ruby-core
  2021-04-08 15:21 ` [ruby-core:103307] " mame
                   ` (18 more replies)
  0 siblings, 19 replies; 21+ messages in thread
From: marcandre-ruby-core @ 2021-04-08 15:08 UTC (permalink / raw)
  To: ruby-core

Issue #17785 has been reported by marcandre (Marc-Andre Lafortune).

----------------------------------------
Feature #17785: Allow named parameters to be keywords
https://bugs.ruby-lang.org/issues/17785

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
We should allow named parameters to be keywords and use add a trailing `_` to the corresponding variable:

```ruby
def check(arg, class:)
  arg.is_a?(class_)
end

check(42, class: Integer) # => true
```

Currently, if we want such an API we have to use `**rest`:

```ruby
def check(arg, **rest)
  class_ = rest.fetch(:class) { raise ArgumentError('missing keyword: :class')}
  if rest.size > 1
    unknown = rest.keys - [:class]
    raise ArgumentError("unknown keyword(s): :#{unknown.join(', :')})
  end

  arg.is_a?(class_)
end
```

This is very verbose, much less convenient, much less readable, prevents `steep` from generating the proper signature, etc.

We should do the same for pattern match.



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

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-12-17 18:10 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 15:08 [ruby-core:103305] [Ruby master Feature#17785] Allow named parameters to be keywords marcandre-ruby-core
2021-04-08 15:21 ` [ruby-core:103307] " mame
2021-04-08 15:23 ` [ruby-core:103308] " zverok.offline
2021-04-08 16:55 ` [ruby-core:103312] " marcandre-ruby-core
2021-04-09 13:04 ` [ruby-core:103346] " jean.boussier
2021-04-09 17:59 ` [ruby-core:103350] " eregontp
2021-04-09 20:57   ` [ruby-core:103354] " Austin Ziegler
2021-04-10  0:06 ` [ruby-core:103360] " duerst
2021-04-10  3:20 ` [ruby-core:103362] " nobu
2021-04-10  7:47 ` [ruby-core:103368] " jean.boussier
2021-04-10 17:04 ` [ruby-core:103377] " marcandre-ruby-core
2021-04-19 19:17 ` [ruby-core:103516] " matheusrichardt
2021-06-09  0:08 ` [ruby-core:104209] " harrison.bachrach
2021-12-02 20:07 ` [ruby-core:106414] " ioquatix (Samuel Williams)
2021-12-13  3:25 ` [ruby-core:106630] " Dan0042 (Daniel DeLorme)
2021-12-13 21:31 ` [ruby-core:106645] " Eregon (Benoit Daloze)
2021-12-14 15:32 ` [ruby-core:106657] " matheusrich (Matheus Richard)
2021-12-14 15:47 ` [ruby-core:106660] " Dan0042 (Daniel DeLorme)
2021-12-14 16:44 ` [ruby-core:106668] " Eregon (Benoit Daloze)
2021-12-17 13:54 ` [ruby-core:106719] " Dan0042 (Daniel DeLorme)
2021-12-17 18:10 ` [ruby-core:106725] " Eregon (Benoit Daloze)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).