From: "zverok (Victor Shepelev) via ruby-core" Date: 2023-12-18T16:08:30+00:00 Subject: [ruby-core:115773] [Ruby master Feature#20070] commas in pattern match Issue #20070 has been updated by zverok (Victor Shepelev). I don't think it would be possible to keep consistency: the difference from `case`/`when` habits is conscious, due to the deconstruction (and that's why we needed another keyword, not improvement to `when` handling). If `,` meant alternatives for array-like patterns, what about hash-like ones? E.g. ```ruby case params in name:, role: # that's not alternatives, right? ``` Another thing to get used to this convention is thinking about right-hand assignment: ```ruby # This always worked a, b = [1, 2] # This works with PM now: a list of patterns, not alternatives for one value [1, 2] => a, b ``` This _is_ indeed inconsistent with `when` and `rescue`, but I don't think there is a good way to reconciliate it (I am though thinking that maybe some slow future changes to the `rescue` can be made, to "truly" pattern-match against errors, but I am not sure yet). ---------------------------------------- Feature #20070: commas in pattern match https://bugs.ruby-lang.org/issues/20070#change-105710 * Author: Dan0042 (Daniel DeLorme) * Status: Open * Priority: Normal ---------------------------------------- In pattern matching, `case v; in 1,2,3` is a synonym for `case v; in [1,2,3]` This is the one thing that keeps confusing me, that I haven't been able to get used to. Because I'm used to `case v; when 1,2,3` it feels like `case v; in 1,2,3` should have a similar meaning. So it's possible to omit the square brackets but honestly I don't see much point for that, it just makes it look to me like something it is not. In other words, I feel it would be far more intuitive (at least to me) if ```ruby case v in 1,2,3 ``` was a synonym for ```ruby case v in 1 in 2 in 3 ``` or possibly a synonym for ```ruby case v in (1|2|3) ``` which would make it similar to the syntax in `rescue A, B, C => err` Is it too late to change this? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/