From: Daniel Baird Date: 2006-03-27T16:10:31+09:00 Subject: Re: Duck typing bunches of strings ------=_Part_7150_7761460.1143443414501 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline maybe you just want anything that has respond_to? :each and isn't a String. From memory String doing Enumerable is a bit of a special case; if you eliminate just String and any of it's subclasses you're probably left with the "real" Enumerables. ;Daniel On 27/03/06, listrecv@gmail.com wrote: > > In my quest to master the fine art of duck typing / overloading, I've > run into this probem: > > How can I identify a collection? > The problem is: String mixes in Enumerable, although it ain't a > collection. > > My method wants to act differently if it's given a collection, then if > it's just given a single object. I would check .respond_to? :each - > but String does, unfortunately. > > Currently, I'm forced to do .kind_of? Array - but this ain't duck > typing. > > Any ideas? I'd like to separate Array, Hash, Set, etc. etc. from > single member objects. > > > -- Daniel Baird http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things That Suck) [[My webhost uptime is ~ 92%.. if no answer pls call again later!]] ------=_Part_7150_7761460.1143443414501--