Bug #10123

Named capture groups don't set local vars when matched using ~

Added by Josh Cheek 11 months ago. Updated 10 months ago.

[ruby-core:64304]
Status:Open
Priority:Normal
Assignee:-
ruby -v:ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0] Backport:2.0.0: UNKNOWN, 2.1: UNKNOWN

Description

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

History

#1 Updated by Nobuyoshi Nakada 10 months ago

  • Description updated (diff)

I'm not sure if this should be a bug or a new feature.

Also available in: Atom PDF