From: J J Date: 2001-05-08T23:41:25+09:00 Subject: [ruby-talk:14868] Re: Polymorphic methods If anyone is interested, I've written a mixin that will give you pseudo-overloaded methods, such that: setN(3) setN('4') will call setNFixnum(3) setNString('4') respectively. Currently supports up to 3 arguments, but is easily extended. It's available at: http://www.johnjohnsonsoftware.com/ruby Regards, JJ -- Be Kind, Be Careful, Be Yourself -- Solid, reliable software at reasonable prices http://www.johnjohnsonsoftware.com "J J" wrote in message news:TbBJ6.31$Qx.5847@newsread1.prod.itd.earthlink.net... > In C++ you can have polymorphic methods such as > > doIt( String s ) { > ... > } > > doIt( Integer i ) { > ... > } > > Is there a way to duplicate this behavior without resorting to: > > def doIt( object ) > if object.type == String > ... > elsif object.type == Numeric > ... > end > end > > I'm thinking of instances (for example) where you can create an object from > several different objects passed to the constructor. E.g. > > m = Month.new(12) > m = Month.new('December') > m = Month.new(anotherMonth) > > thus, Month.initialize has to have a case or if statement. > > Thanks in advance! > > JJ > > -- > Be Kind, Be Careful, Be Yourself > -- > Solid, reliable software at reasonable prices > http://www.johnjohnsonsoftware.com > > > > >