[ruby-core:93871] [Ruby master Feature#10123] Named capture groups don't set local vars when matched using ~
From:
merch-redmine@...
Date:
2019-07-22 21:22:47 UTC
List:
ruby-core #93871
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 `/(?<some>re)/ =~ string` case sets local variables. Even the `string =~ /(?<some>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 '~/(?<initial>\w)/ and puts initial' -e:1:in `<main>': undefined local variable or method `initial' for main:Object (NameError) ~~~ Working when using `=~ $_`: ~~~ $ echo ' josh' | ruby -ne '/(?<initial>\w)/ =~ $_ and puts initial' j ~~~ -- 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>