News for hackers. Stuff that matters.
Re:Pattern Matching in Ruby 2.7 (2019) by RangerScience on Thursday January 09, 2020 @02:27AM (#21999202)
> in function header definition

Hmmm, I can kind of see it, but then you'd also need function overloading, right? With this you'd just do outer/inner functions, where the outer determines the pattern match and dispatches along to the appropriate inner function.

If you want to just make sure the function only accepts arguments that match a pattern, you're basically talking a guard pattern. Maybe a `return unless foo in <pattern>` syntax would then be nice (or some other one-liner), but it's not like it'd be hard to do it using this feature, you'd just use a few more mostly empty lines.

Re:Pattern Matching in Ruby 2.7 (2019) by verttii on Thursday January 09, 2020 @07:07AM (#22000503)
You mean that guards + destructuring would effectively be the same as pattern matching in function's params? Pattern matching would allow matching against more complex data structures more comfortably though.