ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Support binding to non-local vars in pattern matching

Open palkan opened this issue 3 years ago • 2 comments

Examples:

case %w[a b c]
in [@a, $b, *@@rest]
end

@a #=> 'a'
$b #=> 'b'
@@rest #=> ['c']

Using vars in alt pattern is prohibited (similarly to the current behaviour for local vars).

Implements https://bugs.ruby-lang.org/issues/18408.

P.S. This brings back rightward assignment: 42 => @v.

palkan avatar Jan 11 '22 10:01 palkan

Could you add specs for this in spec/ruby/language/pattern_matching_spec.rb ?

eregon avatar Jan 11 '22 14:01 eregon

@eregon Done!

palkan avatar Jan 12 '22 07:01 palkan