On Fri, 02 Mar 2007 10:01:06 +0900, Gary Wright wrote: > On Mar 1, 2007, at 7:38 PM, James Edward Gray II wrote: >> 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. > > Yet if I test for (Hash == mystery_obj) that would not allow someone to > pass an RBTree object instead, which I think is a very reasonable thing > to allow and works just fine if I only use #fetch. > > A minimum interface to an indexable collection might be: > > has_key?(key) > fetch(key) > store(key, val) > > In a quick look it seems like only Hash and RBTree implement those > methods though. Sounds like you want C++200x concept checking, but that depends very heavily on static typing. Basically, I think you want to know (in a non-mutating way) whether #[] supports various types non-integer parameters. I doubt there's any way to do that in Ruby. You could try indexing it and see if it throws a TypeError (like an Array will), but when you call #[] on Hash.new{|h,v| h [v]=0}, #[] is mutating. --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/