On Fri, Jun 24, 2011 at 3:38 PM, Intransition <transfire / gmail.com> wrote:
> Well, for about the first time I am writing a library that has to be
> very strict about types. Per the usual I am testing types with `case`,
> e.g.
>
> =A0 =A0def foo=3D(foo)
> =A0 =A0 @foo =3D \
> =A0 =A0 =A0 case foo
> =A0 =A0 =A0 when Array
> =A0 =A0 =A0 =A0 =A0foo
> =A0 =A0 =A0 when String
> =A0 =A0 =A0 =A0 =A0[foo]
> =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 raise
> =A0 =A0 =A0 end
> =A0 =A0end
>
> Now as I do this it occurs to me, shouldn't I also honor anything that
> responds_to?(:to_ary) as an Array? And if so, what's the "usual" way
> to handle it then?

It depends. Do you want to? I suppose the only disadvantage would be
the cost of an object possibly creating a new array when to_ary is
invoked.

It might be worth letting the user decide with a second `force =3D
false` parameter.

I am also wondering, what makes a String special here as opposed to a
Fixnum or any other object?