From: Dan Doel Date: 2004-04-20T05:22:23+09:00 Subject: Re: How do you know it quacks like a duck? Ah, I see what you're saying. Sorry I misread. Yes, I suppose you would want to check for methods explicitly if you need to treat them differently. That's probably the most efficient way that leaves the question of the actuall class open. All the methods I can think of in the standard library that do different things based on what they're passed, though, actually check the class of the object (I think). Another option would be to do what I said, and split your method into multiple methods, like: def string_foo... def date_foo... def time_foo... But the result probably wouldn't be pretty. Cheers. - Dan On Monday 19 April 2004 3:06 pm, Sam Roberts wrote: > Wrote Dan Doel , on Mon, Apr 19, 2004 at 09:55:43AM +0900: > > Just use it as you would a Time object. > > That doesn't work for me, if you look at my example, I need to know if > it's a Date or a Time, and I need to treat them differently. But, I > would like to support any object which is "date-like" or "time-like". > DateTime, in ruby 1.8, for example, is actually time-like (it has hours, > mins, secs). > > I can see if it's string-like or array-like by checking for #to_str or > #to_ary, but is there a general case? > > Maybe I'll just write a function that checks for the year/mon/day > methods and hour/min/sec methods, to distinguish. > > Cheers, > Sam