diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-05 14:59:46 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-05 14:59:46 +0000 |
commit | 0c792a32b7e600320eb5eb3fd9e3ae1fe57e8b58 (patch) | |
tree | 499504866761bfcca6c3851493d8d345702aeecb /lib/pp.rb | |
parent | 90d8cbb1ee3c7955642e1af995361eb0d9558aa9 (diff) | |
download | ruby-0c792a32b7e600320eb5eb3fd9e3ae1fe57e8b58.tar.gz |
* lib/prettyprint.rb (PrettyPrint#seplist): added.
* lib/pp.rb (PPMethods#pp_object): use seplist.
(PPMethods#pp_hash): ditto.
(Array#pretty_print): ditto.
(Struct#pretty_print): ditto.
(MatchData#pretty_print): ditto.
* lib/set.rb (Set#pretty_print): use seplist.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pp.rb')
-rw-r--r-- | lib/pp.rb | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -203,10 +203,9 @@ class PP < PrettyPrint def pp_object(obj) object_address_group(obj) { - obj.pretty_print_instance_variables.each {|v| - v = v.to_s if Symbol === v - text ',' unless first? + seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v| breakable + v = v.to_s if Symbol === v text v text '=' group(1) { @@ -219,8 +218,7 @@ class PP < PrettyPrint def pp_hash(obj) group(1, '{', '}') { - obj.each {|k, v| - comma_breakable unless first? + seplist(obj, nil, :each_pair) {|k, v| group { pp k text '=>' @@ -279,8 +277,7 @@ end class Array def pretty_print(q) q.group(1, '[', ']') { - self.each {|v| - q.comma_breakable unless q.first? + q.seplist(self) {|v| q.pp v } } @@ -310,8 +307,7 @@ end class Struct def pretty_print(q) q.group(1, '#<struct ' + self.class.name, '>') { - self.members.each {|member| - q.text "," unless q.first? + q.seplist(self.members, lambda { q.text "," }) {|member| q.breakable q.text member.to_s q.text '=' @@ -420,8 +416,7 @@ class MatchData def pretty_print(q) q.object_group(self) { q.breakable - 1.upto(self.size) {|i| - q.breakable unless q.first? + q.seplist(1..self.size, lambda { q.breakable }) {|i| q.pp self[i-1] } } |