From: gabriele renzi Date: 2003-04-26T04:23:41+09:00 Subject: Re: freezing Array/Hash length il Sat, 26 Apr 2003 01:13:29 +0900, "Brett H. Williams" ha scritto:: >First I don't think myarr.last < MAX_LENGTH does what you want: doh! I meant to write "length" not "last".. >At any rate, why not: > >class FixedArray < Array > def push(x) > super(x) if size() < MAX_LENGTH > end > def []=(idx,x) > super(idx,x) if idx < MAX_LENGTH - 1 > end >end > >You'd still have to be careful of other methods that might increase the length >of an array. well, this is a slightly better solution, I just thought that could be something like Array#fix_size that I (and ri) was'nt aware of.. >> [1] damn, I always wanted a variable length array when using java.. > >like a Vector? sure, but doing mine = (mySpecificClass) myVector.elementAt(10) is way worst than my = myArray[10] ^_^ anyway, thanks