[#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:97946] [Ruby master Feature#16796] Assigning local variables when using `case when regexp`
From:
shevegen@...
Date:
2020-04-17 16:38:45 UTC
List:
ruby-core #97946
Issue #16796 has been updated by shevegen (Robert A. Heiler).
sawa wrote:
> I have met such use cases, and agree this would be useful.
I don't disagree in the sense that there may be valid use cases,
but the syntax is kind of weird:
/s(?<mid>.)r/
I use regexes a lot of course, since they are useful. But do we
really gain a lot from making what used to be simple, harder?
I understand that you may avoid an extra step (assignment, after
the regex match), but to me personally I find that style so
much harder to read, compared to:
if /(foo.+)/
mid = $1.to_s.dup # or something like that
end
Admittedly I am very much a very oldschool-ruby person. ;)
By the way, while I personally do not really like $ variables,
I actually use them a LOT, whereas I rarely use match_data[]
syntax style. Dunno why, perhaps a habit, but the $1 $2 etc..
are ony of the few (semi) global variables that I like.
(I write "semi" because they tend to be more volatile, which
is why I may tend to use .dup like a semi-crazy person a
lot, rather than fix a regex or handle nils - I .to_s.dup
all the things! ;) )
----------------------------------------
Feature #16796: Assigning local variables when using `case when regexp`
https://bugs.ruby-lang.org/issues/16796#change-85168
* 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>