From: Marnen Laibow-Koser Date: 2009-11-19T23:31:51+09:00 Subject: Re: dynamic array? Freak Guard wrote: >> So reopen, extend, or subclass Array to get the desired behavior. >> What's the problem? > > class DefaultArray < Array > > attr_accessor :default_value > > def initialize > super > @default_value = nil > end > > def [](idx) > super || @default_value > end > end > > ... and writing all the iterators I need which will be dead slow I > assume :/ I'm not sure you'll need to rewrite the iterators. You may need to store length separately, though, since counting the elements won't do the trick. > > Greetings > FreakGuard Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.