From 9f45dc126cc461b78984383f4c15bfdc80b1f6d5 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 5 Feb 2004 14:59:46 +0000 Subject: * 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 --- lib/prettyprint.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/prettyprint.rb') 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 -- cgit v1.2.3