From: "Dan0042 (Daniel DeLorme) via ruby-core" Date: 2023-12-18T17:03:01+00:00 Subject: [ruby-core:115774] [Ruby master Feature#20070] commas in pattern match Issue #20070 has been updated by Dan0042 (Daniel DeLorme). I understand what you mean but this is not about keeping strict consistency per se. It's a specific case that I find confusing because it does something different from what it looks like to me, based on my personal experience. > ```ruby > case params > in name:, role: # that's not alternatives, right? > ``` It's not alternatives? I guess so, but what it does is not intuitively obvious to me. I would write that code as `in {name:, role:}` to avoid confusion. But you make a good point; there's no equivalent `when` clause so interpreting it as alternatives might be just as confusing. My confusion has to do when commas are used at the "top level" of `case..in`, not so much with `=>` and right-hand assignment. Note that if you put `[1, 2] => a, b` inside a `case..in` it has a considerably different meaning: ```ruby v = [[1,2],3] case v in [1, 2] => a, b p a=>b end #=> {[1, 2]=>3} ``` The above behavior become clearer (imho) when you write the brackets: ```ruby v = [[1,2],3] case v in [[1, 2] => a, b] p a=>b end #=> {[1, 2]=>3} ``` ---------------------------------------- Feature #20070: commas in pattern match https://bugs.ruby-lang.org/issues/20070#change-105711 * 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/