Project

General

Profile

Actions

Bug #12862

closed

Regular Expression Named Group Matching does not work with #{} (Similar? to issue #2778)

Added by Amig0 (Leo Amigud) over 7 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
[ruby-core:77708]

Description

Loading development environment (Rails 4.2.5)

irb(main):001:0> /\$(?<dollars>\d+)\.(?<cents>\d+)/ =~ "$3.67"
=> 0
irb(main):002:0> dollars
=> "3"

BUT:

irb(main):001:0> numbers = '\d+'
=> "\\d+"
irb(main):002:0> /\$(?<dollars>#{numbers})\.(?<cents>\d+)/ =~ "$3.67"
=> 0
irb(main):003:0> dollars
NameError: undefined local variable or method `dollars' for main:Object
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0