From: shyouhei@... Date: 2020-04-17T11:11:18+00:00 Subject: [ruby-core:97940] [Ruby master Feature#16796] Assigning local variables when using `case when regexp` Issue #16796 has been updated by shyouhei (Shyouhei Urabe). sawa (Tsuyoshi Sawada) wrote in #note-2: > 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[1] # => "t" > end > ``` That's too confusing. The following code works today. ```ruby case "str" in /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-85163 * 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: