From: Jean-Hugues ROBERT Date: 2004-05-03T20:23:39+09:00 Subject: Re: The code I forgot to include Hi, Thanks to reading your code I learned that new syntax to create an array: x = Array[1,2,3]. So far I used to do: x = [1,2,3] But using Array.[]() is cool if I want to create a subclass of Array. So I tried: class MyArray < Array def self.[](*a); super[*a] end end x = MyArray[1,2,3] # => NoMethodError: super: no superclass method '[]' I don't understand what is happening because obviously Array.[]() exists. In fact it is the only class method defined by Array: Array.methods( false) # nota: false to avoid inherited methods, not in my Pickaxe MyArray.methods( false) # => ["[]"] in both cases. BTW: In your code you redefine [](a), the instance method, whereas in mine I redefined self.[](*), the class method. I don't think that [](a) gets called at all in your example, only your to_s() is called. ??? Yours, Jean-Hugues At 02:58 03/05/2004 +0900, you wrote: ># My idea of how to convert an array of strings to a string with a specified >delimiter >class MyArrayType1 < Array > def [](a) > puts "Entering MyArrayType1#[](a) -- calling parent" > super a > end > def to_s > s = "" > self.each { |x| > s += "; " if s.length>0 > s += x.to_s > } > s > end >end > >myA1 = MyArrayType1['x1', 'y1'] # uses the Array#[](a) method with an Array >argument and sets > # myA1 to a reference to a new object of >type MyArrayType1 > # which is an Array of two strings, 'x1' >and 'y1' > # with an over-ridden 'to_s' method >puts "myA1 = MyArrayType1['x1', 'y1']; puts myA1.to_s ==> " + myA1.to_s # >==> x1; y1 > > >--- >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/30/2004 ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17