From: Richard Lionheart Date: 2004-04-24T13:29:06+09:00 Subject: Great answers! A few more questions Hi Ara, Great answers. BTW, I had another typo in my original post, which I corrected below. I've got a couple more questions, but if you don't feel like spending any more time on this question, please ignore this post. > join ';' That's a lot better than my procedural code. Works great > myA1 = MyArrayType['x1', 'y1'] (Q1) That worked, but where the heck did you come up with that? Is that documented somewhere? I've got The Pragmatic Programmer/Thomas and The Ruby Way/Fulton and didn't notice that in either work (though I certainly have not read every word of either one.) > Object#puts behaves different if passed an Array, or sub-class of Array In my case, I think I was passing puts the the last expression executed in the to_s method of an Array-subclass object. So I really wasn't passing an Array nor a sub-class of Array. (Q2) Do you agree? Below are several variants of code for this question. (Q3) My last question is how can I make the MyArrayType3 invocation work? MyArrayType1 uses my original code (absent the typo) and is invoked with an array of explicitly quoted strings as you suggest. Works great. MyArrayType2 uses your join expresson and is invoked with an array of explicitly quoted strings as you suggest. Works great. MyArrayType3 uses your join expresson but adds an initialize method so it can be invoked with an array object argument. Fails. (Q4) Why? Again, thanks for your great response. Regards, Richard class MyArrayType1 < Array def to_s s = "" self.each { |x| s += "; " if s.length>0 s += x.to_s } s end end class MyArrayType2 < Array def to_s join '; ' end end class MyArrayType3 < Array def to_s sOut = @s.join '; ' end def intialize(aIn) @s = aIn end end myA1 = MyArrayType1['x1', 'y1'] puts myA1.to_s # x1; y1 myA2 = MyArrayType2['x1', 'y1'] puts myA2.to_s # x1; y1 a3 = %w[x1, y1] myA3 = MyArrayType(a3) # undefined method `MyArrayType' for main:Object (NoMethodError) puts myA3.to_s --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.665 / Virus Database: 428 - Release Date: 4/22/2004