[#97678] [Ruby master Feature#16752] :private param for const_set — bughitgithub@...
Issue #16752 has been reported by bughit (bug hit).
5 messages
2020/04/02
[ruby-core:97940] [Ruby master Feature#16796] Assigning local variables when using `case when regexp`
From:
shyouhei@...
Date:
2020-04-17 11:11:18 UTC
List:
ruby-core #97940
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(?<mid>.)r/ p mid end ``` instead of ```ruby case when /s(?<mid>.)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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>