From: Meino Christian Cramer Date: 2003-09-13T09:44:02+09:00 Subject: Re: Mthod redefinition From: Austin Ziegler Subject: Re: Mthod redefinition Date: Sat, 13 Sep 2003 07:38:09 +0900 Hi Thank you for the explanation of duck typing ! Now I have understood, what these little ducks have to do with ruby programming. Would it be correct if I would say: Duck typing is more or less equal to providing the code for calling the "same" method of different signatures be hand while C++ and other OOP-languages will do this automagically while compiling the code ? Kind regards, Meino > Ferenc's code does, more or less, what Ryan Pavlik's StrongTyping module > does. > > However, with the exception of nil testing, you may feel more comfortable > with duck typing. > > For your simple case, it might be: > > class Bar > def foo(arg = nil) > return "Who gives no input will get no output." if arg.nil? > return "One gives me #{arg}." > end > end > > arg is, of course, not limited to integers at this point. The question would > then become what is it that you wish to do with integers that you need the > value? > > Duck typing is based mostly on realising what sort of operations you want to > do with the object and testing for those operations, rather than testing for > the class. As Dave is fond of saying: type and class aren't the same. > > -austin > -- > austin ziegler * austin@halostatue.ca * Toronto, ON, Canada > software designer * pragmatic programmer * 2003.09.12 > * 18.29.32 > > > > >