From: "Brian Schröder" Date: 2005-06-01T19:03:25+09:00 Subject: Re: array of object insert polices On 01/06/05, dave wrote: > > > It gets uglier as you go on :-):-) .... So you may have to listen to > RobertK's idea also. > > which are (all) the methods should i filter? > []=, <<.. > > ------------------------- > class IA < Array > def ensure_int(obj) > raise TypeError, "Not an int: #{obj.inspect}" unless (Integer === obj) > end > > def []= (index, other) > ensure_int(other) > super index, other > end > end > ---------------------------------- > > isn't there any hack for this dirty work? > > You should have a look at the thread: Uniform vector class, inheriting from Array: How to make sure that methods return a Vector and not an Array? http://groups-beta.google.com/group/comp.lang.ruby/browse_frm/thread/8d339eecc8624556/4fafe7b359e0fcfb?q=uniform+vector+class&rnum=1&hl=en#4fafe7b359e0fcfb regards, Brian > -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/