From: Robert Klemme Date: 2005-06-01T20:45:22+09:00 Subject: Re: array of object insert polices 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. This is what happens if you calculate the product on an array that contains non numeric values: 13:21:05 [source]: irbs >> values=[1,2,3,"4"] => [1, 2, 3, "4"] >> product = values.inject(1) {|x,e|x*e} TypeError: String can't be coerced into Fixnum from (irb):2:in `*' from (irb):2 from (irb):2:in `inject' from (irb):2:in `each' from (irb):2:in `inject' from (irb):2 > >> "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? Definitely. > help me, please. Maybe you can be a bit more specific on what exactly you are trying to achieve and then people can come up with more concrete answers. Kind regards robert