From: Kristof Bastiaensen Date: 2004-04-24T18:04:06+09:00 Subject: Re: Problem assigning an Array object to an Array-subclass object On Fri, 23 Apr 2004 11:15:16 -0400, Richard Lionheart wrote: > notes =< I didn't like to_s' output for an Array of strings. > Array#to_s simply concatenated them > or inserted a comma separator. > So I wrote my own. > > class MyArrayType < Array > def to_s > print "Starting MyArrayType#to_s" > s = "" > s.each { |x| s += "; " if s.length>0; s += x.to_s } > s > end > end > > myA1 = MyArrayType.new > myA1 = %w[x1, y1] > puts myA1.to_s # x1,y1 .... expected x1; x2 .... MyArrayType#to_s not > invoked > Hi, if all you want to do is change the to_s method, why not just add it to Array? class Array def my_to_s join("; ") end end a = %w[x1 y1] puts a.my_to_s #note (you could even replace the to_s method)