From: "vzvu3k6k (vzvu3k6k _)" Date: 2013-11-29T23:23:01+09:00 Subject: [ruby-core:58701] [ruby-trunk - Feature #9179][Open] MatchData#values_at should support named capture Issue #9179 has been reported by vzvu3k6k (vzvu3k6k _). ---------------------------------------- Feature #9179: MatchData#values_at should support named capture https://bugs.ruby-lang.org/issues/9179 Author: vzvu3k6k (vzvu3k6k _) Status: Open Priority: Normal Assignee: Category: regexp Target version: =begin Using (({MatchData#[]})), we can access a named capture by its name. /(?...)/.match("foo")[:a] #=> "foo" /(?...)/.match("foo")["a"] #=> "foo" But (({MatchData#values_at})) accepts only Integer and refuses Symbol or String. /(?...)/.match("foo").values_at(:a) # I expected it returns ["foo"], but... #=> in `values_at': no implicit conversion of Symbol into Integer (TypeError) /(?...)/.match("foo").values_at("a") #=> in `values_at': no implicit conversion of String into Integer (TypeError) (These are tested in ruby 2.1.0dev (2013-11-28 trunk 43903) [i686-linux].) I think (({MatchData#values_at})) should work along with (({MathData#[]})) as follows: /(?...)/.match("foo").values_at(:a) #=> ["foo"] /(?...)/.match("foo").values_at("a") #=> ["foo"] In the patch, (({match_entry})) is removed because it is no longer used. Comments and code are based on (({rb_hash_values_at})) in hash.c. It passes (({make test-all})) except (({TestGc#test_gc_reason})), which fails also on the original version. =end -- http://bugs.ruby-lang.org/