From: Freak Guard Date: 2009-11-20T00:59:14+09:00 Subject: Re: dynamic array? Marnen Laibow-Koser wrote: > > Hmmm...another approach: > > class DynamicArray < Hash > attr_reader :length > > def initialize(length) > @length = length > super() {[]} > end ... which doesn't fulfull the inital target of to not have to set the length static :) > def []=(i, value) > super > @length = [i + 1, length].max > end > > def to_a > (0..length).to_a.collect{|i| self[i]} > end > > def each(&block) > self.to_a.each block > end > end > > ...and delegate everything else to self.to_a. Probably I'll just implement length as a method and it should work. -- Posted via http://www.ruby-forum.com/.