From: Kyle Schmitt Date: 2008-09-25T22:31:24+09:00 Subject: Re: Getting the right class with inheritance and super() On Wed, Sep 24, 2008 at 9:09 PM, David Masover wrote: > Maybe it's just me, but I often use encapsulation, instead. Humm. It is a good possibility.. > class FixedSizeArray > def initialize(size=1,fill=nil) > # Old duck-typing habit: kind_of, not is_a > if size.kind_of? Array > @array = size # Not duplicated -- careful. > else > @array = Array.new(size, fill) > end > # Why return self here? FixedSizeArray.new will always > # return the new object. Return value here is ignored. This was a cleaned out version of the code, there was other cruft between the end of the if block and the initialize method :) that's the only reason, but it's a very good point. > end > Also, does this graphing tool need to be fast? If not -- if I understand what > you're trying to do -- you might consider simply shrinking it down to size > (with a single slice call) when you need it. One line is a lot easier to > write than a whole class. The graphing tool just needs to be fast enough to graph in the incoming data, which means rendering at perhaps 5 frames per second. Not fast at all. The resizing code isn't meant to be run many times, I figured if you're using an array of fixed size, you're going to set the size very very rarely. The important bits are the ability to append, add and subtract from the array without changing it's size. Thanks. --Kyle