From: Mark Sparshatt Date: 2004-04-29T04:05:20+09:00 Subject: Re: Last minute details Richard Lionheart wrote: >Hi Dick, > >I think I'm on top of the subtleties involved with my question: > >1. I dropped the initial assignments to a and b, because no matter what >they refer to (empty array, string, whatever), they'll be assigned new >references by the subsequent assignments. I confirmed this by adding a puts > >2. I initially dropped the "my_" prefix to to_s, since it looked more >elegant (to me, at least). But when testing, I found now way to undo that >change to Array so that unexpected results would probably obtain in extended >use of my revised approach. > > > if you want to save the old version of to_s you can use the alias method class Array # Override to_s alias old_to_s to_s def to_s join("; ") end end then you can access the old to_s behaviour by using the old_to_s method. Or if you want to change to_s back to it's default behaviour you can use class Array alias to_s old_to_s end i.e. a = %w( foo bar ack) puts "After assignment \"a = %w( foo bar ack)\", a.class.to_s = #{a.class.to_s}" b = %w(eeny meeny miney mo) puts "Before override: a = #{a.to_s}, b = #{b.to_s}" class Array # Override to_s alias old_to_s to_s def to_s join("; ") end end puts "After override: a = #{a.to_s}, b = #{b.to_s}" class Array alias to_s old_to_s end puts "After re-override: a = #{a.to_s}, b = #{b.to_s}" results=<