From: Issac Trotts Date: 2001-12-14T01:52:48+09:00 Subject: [ruby-talk:28421] Re: The maddening output of Arrays OK, how about this: ## # print out Arrays Python-style class Array def to_s self.inspect end end ## # puts Arrays Python-style alias oldputs puts def puts(obj) if obj.kind_of? Array oldputs(obj.inspect) else oldputs(obj) end end > -----Original Message----- > From: David Alan Black [mailto:dblack@candle.superlink.net] > Sent: Thursday, December 13, 2001 6:11 AM > To: ruby-talk@ruby-lang.org > Subject: [ruby-talk:28409] Re: The maddening output of Arrays > > > Hi -- > > On Thu, 13 Dec 2001, Issac Trotts wrote: > > > It's a good thing Ruby makes this so easy to fix: > > > > class Array > > def to_s > > self.inspect > > end > > end > > The snag with that is that it doesn't propagate to #puts: > > irb(main):019:0> class Array; def to_s; inspect; end; end > nil > irb(main):020:0> a = [1,2,3] > [1, 2, 3] > irb(main):021:0> print a > [1, 2, 3]nil # OK, what you want > irb(main):022:0> puts a > 1 # Not what you want > 2 > 3 > nil > > > This is the thing that Matz mentioned he recently experimented with > changing but ended up deciding not to. It's specific to Array: that > is, #puts has special handling for Array and its subclasses. (I'm > still trying to come up with a way to change this that Matz will > accept :-) > > > David > > -- > David Alan Black > home: dblack@candle.superlink.net > work: blackdav@shu.edu > Web: http://pirate.shu.edu/~blackdav >