From: gabriele renzi Date: 2005-09-26T14:56:42+09:00 Subject: Re: Overloading Edward Faulkner ha scritto: > On Mon, Sep 26, 2005 at 10:38:16AM +0900, Ben wrote: > >>The options I see are: >> >>1) Call .class.to_s on each parameter to match the type: >> "pattern.class.to_s =~ /Array/ then # I have an array of regexp > > > You can do this: > > if pattern.class == Array # then ... maybe just if pattern.is_a? Array > Or this: > > case pattern > when Array > # handle array > when Regexp > # handle Regexp > end or, use the case-equality method directly: if pattern === Array Anyway, I think it would be better to have two different methods. Given that ruby does not have multiple dispatch, if you ever want to add another option (i.e. build from an Enumerable) if you hardwire type checks you'll have to change the method code. This is especially bad in the face of subclassing, since you actually have to copy/paste the code. If you, instead, have different methods for the options, you class would stay open for changes.