On Mar 1, 2007, at 6:31 PM, Gary Wright wrote:

> class A
>   def initialize(arg, &b)
>   case
>   when arg.respond_to?(:nonzero?)
>     # do construction based on integer-like behavior

Floats have nonzero?() too.  I really think picking arbitrary methods  
like this to find a type is a big mistake.

You're still type checking, you're just doing it in a more fragile  
way.  If you want to type check, use the class, I say.

If you want it to be an Integer, ask it if it can:

   Integer(...) rescue # nope...

>   when arg.respond_to?(:fetch)
>     # do construction based on hash-like behavior

Arrays have fetch too.

>   when arg.respond_to?(:to_str)
>     # do construction based on string-like behavior

String(...) rescue # nope...

>   else
>     # punt
>   end
> end

James Edward Gray II