Dossy <dossy / panoptic.com> writes:

> On 2002.09.21, Tom Gilbert <tom / linuxbrit.co.uk> wrote:
> > * Dossy (dossy / panoptic.com) wrote:
> > > On 2002.09.20, Khurram <khabibiuf / hotmail.com> wrote:
> > > > How can I check hash keys and values without case sensitivity?
> > > > Specifically I'm referring to the hash ".has_key?" and ".has_value?"
> > > > methods.  I believe these are case sensitive by default.
> > > 
> > >     class Hash
> > >       def has_ikey?(key)
> > >         self.keys.map { |key| key.upcase }.member? key.upcase
> > >       end
> > >     end
> > 
> > Doesn't iterating through all the keys on a lookup kindof take away the
> > advantages of a hashtable? :)
> 
> If you're looking for case insensitive hashes you're already
> going to hell.
> 
> Isn't the whole constraint of a hashtable is that it's case sensitive?

if you do not need the case-information of your hash-keys at all you
could mangle the key to lowercase in the []= and [] methods

class Hash_I < Hash

  alias get_old []
  alias set_old []=

  def [](key)
    return get_old(key.to_s.upcase)
  end

  def []=(key, value)
    return set_old(key.to_s.upcase, value)
  end

end


if i needed both (case-sensitive keys *and* case-insensitive member?-
lookups), i would use a second auxiliary-hash in the class above.

regards
messju

> -- Dossy