Hi --

On Tue, 24 Sep 2002, Gavin Sinclair wrote:

> ----- Original Message -----
> From: "Yukihiro Matsumoto" <matz / ruby-lang.org>
>
> >
> > |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.
> >
> > Why not simply
> >
> >  h.key?(k.upcase)
> >  h.value?(v.upcase)
> >
> > matz.
>
> This has got to be the best solution, as it takes account of the important fact
> that noone else has yet mentioned: Hash keys are not necessarily Strings.

What if the key you used is lowercase?  like this:

  irb(main):002:0> h = {"a" => 1}
  {"a"=>1}
  irb(main):003:0> k = "a"
  "a"
  irb(main):004:0> h.key?(k)
  true
  irb(main):005:0> h.key?(k.upcase)
  false


David

-- 
David Alan Black                      | Register for RubyConf 2002!
home: dblack / candle.superlink.net     | November 1-3
work: blackdav / shu.edu                | Seattle, WA, USA
Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com