Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
alex opened this Issue · 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
Owner

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

@alex

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

@brixen
Owner

@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 closed this in 107c4c2
@chulkilee chulkilee referenced this issue from a commit in chulkilee/rubocop
@yujinakayama yujinakayama Work around to the Rubinius' named capture bug
This is a quick fix for this failing build.
https://travis-ci.org/bbatsov/rubocop/jobs/9148060

The issue is already reported but does not seem to be fixed.
rubinius/rubinius#2051
ccf5fb9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.