From: Chris Uzdavinis Date: 2001-05-08T08:11:24+09:00 Subject: [ruby-talk:14828] Re: Polymorphic methods "J J" writes: > In C++ you can have polymorphic methods such as > > doIt( String s ) { > ... > } > > doIt( Integer i ) { > ... > } That's not polymorphism, that's function overloading. :) > 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! I'd like to know how to do that in ruby too, but my impression is that you just have to test the type. A hash may be faster than a linear search if you have lots of potential types, but it's still testing type. But if there is a way (and I'm often surprised by ruby's capabilitiess), that would be useful. -- Chris