Wrong precedence of the if modifier in pattern matching
When "If" is used as an "If modifier" it runs before the expression that it wraps:
=> puts 1 if (puts 2; true) 2 1
However, when it's used in the pattern matching destructuring runs first:
class A def deconstruct puts 'deconstruct called'  end end p case A.new in A if (puts 'if check'; true) 'yes' else 'no' end # prints # deconstruct called # if check # "yes"
I personally think that it's very confusing as it doesn't reflect the code. I assumed it to not run destructuring if the check returns
false (especially because destructuring is allowed to have side-effects)
Updated by duerst (Martin Dürst) 10 months ago
It's clear that the order of evaluation has to be the way it is currently. But in this case,
if just sounds wrong, not only because of examples such as
puts 1 if condition, but also because of general English.
So I think changing
if to something else is highly desirable. But I unfortunately don't have any good proposal.