From: Jeremy Heiler Date: 2011-06-25T04:57:23+09:00 Subject: Re: Honoring #to_ary and such On Fri, Jun 24, 2011 at 3:38 PM, Intransition 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. > >    def foo=(foo) >     @foo = \ >       case foo >       when Array >          foo >       when String >          [foo] >       else >         raise >       end >    end > > 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 = false` parameter. I am also wondering, what makes a String special here as opposed to a Fixnum or any other object?