From: sawadatsuyoshi@... Date: 2020-04-17T10:20:46+00:00 Subject: [ruby-core:97939] [Ruby master Feature#16796] Assigning local variables when using `case when regexp` Issue #16796 has been updated by sawa (Tsuyoshi Sawada). I have met such use cases, and agree this would be useful. Alternatively, in order to access even unnamed matches, assigning the last matched data to a variable with the following syntax may be useful. ```ruby case "str" when /s(?.)r/ => match_data match_data[:mid] # => "t" end ``` ```ruby case "str" when /s(.)r/ => match_data match_data[1] # => "t" end ``` ---------------------------------------- Feature #16796: Assigning local variables when using `case when regexp` https://bugs.ruby-lang.org/issues/16796#change-85162 * Author: UlyssesZhan (������ ���) * Status: Open * Priority: Normal ---------------------------------------- I want to use ```ruby case "str" when /s(?.)r/ p mid end ``` instead of ```ruby case when /s(?.)r/ =~ "str" p mid end ``` I also do not like using `$1`. This feature is extremely useful when there are a lot of `when`s. -- https://bugs.ruby-lang.org/ Unsubscribe: