From: Dale Martenson Date: 2006-11-03T01:52:46+09:00 Subject: Re: PP / PrettyPrint annoyances Elliot Winkler wrote: > This behavior is sort of ridiculous in my opinion. I'd rather have > something > more like: > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, > 20, > 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, > 39, 40] The problem with 'pp' in my opinion is the mysterious 'breakable'. What you can do is omit the and handle end of line cases in different manner. Someday I may look at changing 'breakable', but for now this works. << START OF CODE require 'pp' class PP def comma text ',' end def comma_newline text ",\n" end def seplist_with_limit(list, limit=20, item_sep=nil, line_sep=nil, iter_method=:each) item_sep ||= lambda { comma } line_sep ||= lambda { comma_newline } count = 0 first = true list.__send__(iter_method) { |v| if count % limit == 0 if first first = false else line_sep.call end else item_sep.call end yield(v) count += 1 } end end class Array def pretty_print(q) q.group(1, '[', ']') { q.seplist_with_limit(self, 20) { |v| q.pp v } } end end pp (0..20).to_a pp (0..40).to_a >> END OF CODE -- Posted via http://www.ruby-forum.com/.