summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-02-05 14:59:46 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-02-05 14:59:46 +0000
commit9f45dc126cc461b78984383f4c15bfdc80b1f6d5 (patch)
tree7e25fe244595c7850d5bf03a30ee5520e76eddae
parentc3c6d7cbca3ec28f2f9133f2fd1d5c158c8a0929 (diff)
* 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/branches/ruby_1_8@5623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--lib/pp.rb17
-rw-r--r--lib/prettyprint.rb13
-rw-r--r--lib/set.rb9
4 files changed, 32 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 7373457f13..fe25883cfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Thu Feb 5 23:56:55 2004 Tanaka Akira <akr@m17n.org>
+
+ * 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.
+
Wed Feb 4 02:12:06 2004 Tanaka Akira <akr@m17n.org>
* file.c (test_l): fix wrong method name in document.
diff --git a/lib/pp.rb b/lib/pp.rb
index 8d8e640275..81a453d9ab 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -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]
}
}
diff --git a/lib/prettyprint.rb b/lib/prettyprint.rb
index 70b6da7924..6f2c8ea7cc 100644
--- a/lib/prettyprint.rb
+++ b/lib/prettyprint.rb
@@ -159,6 +159,19 @@ class PrettyPrint
@group_stack.last
end
+ def seplist(list, sep=nil, iter_method=:each)
+ sep ||= lambda { comma_breakable }
+ first = true
+ list.__send__(iter_method) {|*v|
+ if first
+ first = false
+ else
+ sep.call
+ end
+ yield(*v)
+ }
+ end
+
def first?
current_group.first?
end
diff --git a/lib/set.rb b/lib/set.rb
index a19a4f3b55..e9c6931b14 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -418,14 +418,7 @@ class Set
def pretty_print(pp) # :nodoc:
pp.text sprintf('#<%s: {', self.class.name)
pp.nest(1) {
- first = true
- each { |o|
- if first
- first = false
- else
- pp.text ","
- pp.breakable
- end
+ pp.seplist(self) { |o|
pp.pp o
}
}