summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-09 21:44:19 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-09 21:44:19 +0000
commit08eb58d3dd6543a44c798aacc4385bf9f8bc005d (patch)
treeea01c61d89a34db40e21b9888d35ffe63d656754 /lib
parent9d8075b99cf131e0b2522bcf82a5b47e82d3882e (diff)
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/pp.rb18
1 files changed, 16 insertions, 2 deletions
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