[ruby-core:102891] [Ruby master Feature#17718] a method paramaters object that can be pattern matched against
From:
dsisnero@...
Date:
2021-03-16 23:52:46 UTC
List:
ruby-core #102891
Issue #17718 has been updated by dsisnero (Dominic Sisneros).
def get_param(name, city: nil, state:nil, zip: nil, &error)
case parameters_match
in [String, String, String , String, Proc]
puts 'all method types matched against'
in [String, nil, String, nil,nil]
puts 'only city and state matched'
end
end
I don't only want to match on keywords. I want to use an object to make it easy ruby methods like multimethods
----------------------------------------
Feature #17718: a method paramaters object that can be pattern matched against
https://bugs.ruby-lang.org/issues/17718#change-90952
* 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>