From: merch-redmine@... Date: 2019-07-22T21:22:47+00:00 Subject: [ruby-core:93871] [Ruby master Feature#10123] Named capture groups don't set local vars when matched using ~ Issue #10123 has been updated by jeremyevans0 (Jeremy Evans). Backport deleted (2.0.0: UNKNOWN, 2.1: UNKNOWN) ruby -v deleted (ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]) Tracker changed from Bug to Feature Looking at the documentation for Regexp#=~ as well as the Capture section of the Regexp class documentation, both of which describe assignment of named captures to local variables, it seems intentional that only the `/(?re)/ =~ string` case sets local variables. Even the `string =~ /(?re)/` case does not set them. So I think this should be considered a feature request. ---------------------------------------- Feature #10123: Named capture groups don't set local vars when matched using ~ https://bugs.ruby-lang.org/issues/10123#change-79819 * Author: josh.cheek (Josh Cheek) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Broken when using `~`: ~~~ $ echo ' josh' | ruby -ne '~/(?\w)/ and puts initial' -e:1:in `
': undefined local variable or method `initial' for main:Object (NameError) ~~~ Working when using `=~ $_`: ~~~ $ echo ' josh' | ruby -ne '/(?\w)/ =~ $_ and puts initial' j ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: