[#106341] [Ruby master Bug#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" } — dorianmariefr <noreply@...>
Issue #18369 has been reported by dorianmariefr (Dorian Mari辿).
14 messages
2021/11/30
[#106351] [Ruby master Bug#18371] Release branches (release information in general) — "tenderlovemaking (Aaron Patterson)" <noreply@...>
Issue #18371 has been reported by tenderlovemaking (Aaron Patterson).
7 messages
2021/11/30
[ruby-core:105948] [Ruby master Feature#18291] When use =~ with named group, if regex is on the right side, variable not defined.
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2021-11-05 15:21:48 UTC
List:
ruby-core #105948
Issue #18291 has been updated by jeremyevans0 (Jeremy Evans). Backport deleted (2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN) Tracker changed from Bug to Feature `regexp.rdoc` documents that the literal regexp must be on the left hand side in order to assign to local variables, so this is not a bug. Switching to feature request. ---------------------------------------- Feature #18291: When use =~ with named group, if regex is on the right side, variable not defined. https://bugs.ruby-lang.org/issues/18291#change-94494 * Author: zw963 (Wei Zheng) * Status: Open * Priority: Normal ---------------------------------------- Following code not work. ```rb if "Billy Zheng" =~ /(?<first_name>\w+)\s+(?<last_name>\w+)/ p first_name p last_name end # NameError: undefined local variable or method `first_name' for main:Object ``` But, if we switch left and right between =~ ```rb if /(?<first_name>\w+)\s+(?<last_name>\w+)/ =~ "Billy Zheng" p first_name p last_name end # => "Billy" # =>"Zheng" ``` I know ruby keep this same behavior since 1.9, but i am curious if we can improve this? I consider this as a bug, because that not good, when i want to use this way, i have to take care must write regexp before =~ Thank you. -- 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>