From: "Brian Schröder" Date: 2005-06-01T20:42:53+09:00 Subject: Re: array of object insert polices On 01/06/05, dave wrote: > > > > You should have a look at the thread: > > Uniform vector class, inheriting from Array > > > Duck typing. Code that relies on ints in there will soon discover if > > someone puts something non numeric in there. > > I had a look at Chapter 23 Duck Typing of Programming Ruby. > > I understand that i haven't to validate imput type, this let me > a little bit lost. > > >"Code that relies on ints will discover" > ..and what if i write a class to calculate a productory and who uses > this class see something like that on the monitor: > > "i'm an integer Hahhaaai'm an integer Hahhaaai'm an integer Hahhaaai'm an > integer Hahhaaai'm an integer Hahhaaai'm an integer Hahhaaai'm an integer > Hahhaaai'm an integer Hahhaaai'm an integer Hahhaaa" > > (he wronged to parse an imput file `integers: 3 3`). > > maybe unit tests can help me? > > help me, please. > > If you parse string input that should be converted to int you would normally validate the input. Take for example a look at the highline library for this purpose. And what should the unit do if it is used in a wrong way? Throwing and exception is normally a good idea. And this can be achieved simple by method missing errors. best regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/