It seems to me that listing (#keys) and iterating through (#each_pair) its
values is a key (excuse the pun) part of a hash's job.

Then again, maybe your hash-like objects aren't hashes in this way. The
question changes if you change the definition of "hash-like".

Is it un-rubyish to use #is_a to do this? i.e. define a module or superclass
for your hash-likes? It may even be useful to include some of this extra
hash-related functionality in a mixin; e.g. define #keys and get #each_pair
for free.

"Sean O'Dell" <sean / celsoft.com> wrote in message
news:200406041915.32644.sean / celsoft.com...
> On Friday 04 June 2004 18:34, nobu.nokada / softhome.net wrote:
> > Hi,
> >
> > At Sat, 5 Jun 2004 10:13:44 +0900,
> >
> > Florian Gross wrote in [ruby-talk:102433]:
> > > > So, how do I positively identify when an object is a hash or at
least
> > > > behaves like a hash?
> > >
> > > obj.respond_to?(:keys) # ? :)
> >
> > I'd prefer :each_pair.
>
> In both cases, does that mean that the object has hash-like functionality,
or
> just that the object responds to those two methods?  Is there some
definition
> somewhere that says "it's a hash if it has these methods?"  I actually
have
> hash-like objects that DON'T respond to either of those two methods, but
it
> would be easy enough to add fake ones.  I hate adding fake methods just to
id
> a hash interface, it's a kludge.
>
> Sean O'Dell
>
>