Project

General

Profile

Feature #9253

Regexp named match and case statement

Added by Olivier El Mekki almost 3 years ago. Updated over 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
[ruby-core:59139]

Description

Hello,

I've notice there's no mean to use captured named matches with case
statement :

> a, b = "foo bar", nil
=> ["foo bar", nil]

>   case a
>     when /foo (?<b>bar)/ then p b
>   end
nil

This is not critical, because we can use $1, $2 and friends in place, but it
certainly would be nice and less surprising if it worked.

NB : btw, the link "How to report" [1] from tracker home page [2] is a 404.

[1] https://bugs.ruby-lang.org/projects/ruby/wiki/HowtoReport
[2] https://bugs.ruby-lang.org/

History

#1 [ruby-core:59140] Updated by Yusuke Endoh almost 3 years ago

There is a way to capture it: use $~[:b] instead of b. Nonetheless, I like this proposal.

--
Yusuke Endoh mame@tsg.ne.jp

#2 [ruby-core:59156] Updated by Olivier El Mekki almost 3 years ago

I didn't know of this syntax, thanks Yusuke.

mame (Yusuke Endoh) wrote:

There is a way to capture it: use $~[:b] instead of b. Nonetheless, I like this proposal.

--
Yusuke Endoh mame@tsg.ne.jp

#3 [ruby-core:59382] Updated by Robert A. Heiler over 2 years ago

Indeed, I did not know of $~[:b] either. Quite nice.

#4 [ruby-core:60254] Updated by Hiroshi SHIBATA over 2 years ago

  • Target version changed from 2.1.0 to current: 2.2.0

Also available in: Atom PDF