From 08eb58d3dd6543a44c798aacc4385bf9f8bc005d Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 9 Dec 2007 21:44:19 +0000 Subject: * re.c (rb_reg_names): new method Regexp#names. (rb_reg_named_captures): new method Regexp#named_captures (match_regexp): new method MatchData#regexp. (match_names): new method MatchData#names. * lib/pp.rb (MatchData#pretty_print): show names of named captures. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/pp.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pp.rb b/lib/pp.rb index 74f690e9f8..ec896b3ce5 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -473,10 +473,24 @@ end class MatchData def pretty_print(q) + nc = [] + self.regexp.named_captures.each {|name, indexes| + indexes.each {|i| nc[i] = name } + } q.object_group(self) { q.breakable - q.seplist(1..self.size, lambda { q.breakable }) {|i| - q.pp self[i-1] + q.seplist(0...self.size, lambda { q.breakable }) {|i| + if i == 0 + q.pp self[i] + else + if nc[i] + q.text nc[i] + else + q.pp i + end + q.text ':' + q.pp self[i] + end } } end -- cgit v1.2.3