diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-09 21:44:19 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-09 21:44:19 +0000 |
| commit | d64e9d6b38bc7acf26a4ba4d91403d1c9135d20a (patch) | |
| tree | ea01c61d89a34db40e21b9888d35ffe63d656754 /lib | |
| parent | 0495fa3b0e1f7486cefef29c155af2ba1415ee36 (diff) | |
| download | ruby-d64e9d6b38bc7acf26a4ba4d91403d1c9135d20a.tar.gz ruby-d64e9d6b38bc7acf26a4ba4d91403d1c9135d20a.tar.xz ruby-d64e9d6b38bc7acf26a4ba4d91403d1c9135d20a.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@14163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pp.rb | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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 |
