literal regexp matches with named captures do not create local variables #2051

Closed
alex opened this Issue Nov 24, 2012 · 4 comments

3 participants

@alex

Example:

unknownc8bcc8a5a0c2:pypy alex_gaynor$ ruby-1.9.3-p125 -e "/(?<lhs>\d+)/ =~ '12'; puts lhs"
12
unknownc8bcc8a5a0c2:pypy alex_gaynor$ rbx-head -X19 -e "/(?<lhs>\d+)/ =~ '12'; puts lhs"
An exception occurred evaluating command line code
    undefined local variable or method `lhs' on an instance of Object. (NameError)

Backtrace:
          Kernel(Object)#lhs (method_missing) at kernel/delta/kernel.rb:81
                     { } in Object#__script__ at -e:1
  Rubinius::BlockEnvironment#call_on_instance at kernel/common/block_environment.rb:75
                Kernel(Rubinius::Loader)#eval at kernel/common/eval.rb:75
                       Rubinius::Loader#evals at kernel/loader.rb:583
                        Rubinius::Loader#main at kernel/loader.rb:814

This is documented here: http://www.ruby-doc.org/core-1.9.3/Regexp.html#method-i-3D-7E

@brixen
Rubinius member

Why don't you file issues for easy things. :)

@alex

@brixen Next time I'll file out about regexp and encodings :(

@brixen
Rubinius member

@alex oh, you want to play like that, huh? :)

@agrimm

+1 for compatibility with Ruby 1.9.1. https://github.com/ruby/ruby/blob/ruby_1_9_1/re.c#L2554

@dbussink dbussink added a commit that closed this issue Jul 21, 2013
@dbussink dbussink Setup locals from Regexp =~
Fixes #2051 and #2466
107c4c2
@dbussink dbussink closed this in 107c4c2 Jul 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment