On Thu, Jan 27, 2011 at 4:20 AM, David Masover <ninja / slaphack.com> wrote:

> On Wednesday, January 26, 2011 02:52:12 pm Tony Arcieri wrote:
> > Just a small nitpick:
> >
> >   if other.is_a? TimeInterval
> >     TimeInterval.new(value + other.value)
> >   elsif other.is_a? Numeric
> >     TimeInterval.new(value + other)
> >   else
> >     raise TypeError, "#{other.class} can't be coerced into TimeInterval"
> >   end
> >
> > would probably be better written as:
> >
> >   case other
> >   when TimeInterval
> >     TimeInterval.new(value + other.value)
> >   when Numeric
> >     TimeInterval.new(value + other)
> >   else raise TypeError, "#{other.class} can't be coerced into
> TimeInterval"
> >   end
>
> Or at least:
>
> if other.kind_of? TimeInterval
>  ...
> elsif other.kind_of? Numeric
>  ...
>
> Remember duck typing? I don't care if it is_a Numeric, not really. I can't
> really think of many cases where is_a? makes more sense than kind_of?.
>
>
Am I missing something here? I don't see how this is in keeping with the
idea of duck typing: is_a? is an alias for kind_of? and vice-versa.

http://www.ruby-doc.org/core/classes/Object.html#M001034

Perhaps you were thinking of instance_of? here?