Issue #17718 has been updated by Dan0042 (Daniel DeLorme).


nobu (Nobuyoshi Nakada) wrote in #note-3:
> I think there was a proposal for a similar concept, "rest keywords including all keywords", but can't find it now.

I believe you're talking about #15049. In #16253 there was brief talk of making argument forwarding work like that so we could use `Hash[...]`, but unfortunately that option that not retained.

But in this particular case I think it wouldn't work anyway; let's say you use `get_perdiem(state: 'CA')` then I would expect `parameters_match` to return all parameters including their default values like `{city: nil, state: 'CA', zip:nil}`. And that would match `in {zip: zip}` unlike what the OP intends. Or use `parameters_match.compact` like Hanmac suggests.

----------------------------------------
Feature #17718: a method paramaters object that can be pattern matched against
https://bugs.ruby-lang.org/issues/17718#change-91056

* Author: dsisnero (Dominic Sisneros)
* Status: Open
* Priority: Normal
----------------------------------------
```ruby
def get_perdiem(city: nil, state: nil, zip:nil)

  case parameters_match  # (return an object of the parameters we can pattern match on)
  in {zip: zip}
     find_perdiem_by_zip(zip)
  in {state: s, city: c}
     find_perdiem_by_state_and_city(s, c)
  in { state: s}
     find_perdiem_by_state(s)
  else
     raise 'need combination of zip, city,state'
  end
end
```



-- 
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>