From: "Jesús Gabriel y Galán" Date: 2008-04-16T03:06:38+09:00 Subject: Re: Hash or bidimensional Array when key is case insensitive? On Tue, Apr 15, 2008 at 6:31 PM, Iñaki Baz Castillo wrote: > Hi, I've to take a decission about using an bidimensional Array or a > Hash to store parameters. Of course I prefer Hash since the order > doesn't matter and I know the param name I'll need. > The problem is that the param name is case insensitive. > > Example: > > tag = qweqweqwe > Method = INVITE > NAT=yes > > is the same as: > > Tag = qweqweqwe > METHOD = INVITE > Nat=yes > > If I use an bidimensional Array and need to get "method" param I willl > need to do: > > method = params_array.find { |param| param[0] =~ /^method$/i }[1] > > And if I use a Hash I'll do the same: > > method = params_hash.find { |param| param[0] =~ /^method$/i }[1] > > Is there any advantage using Array or Hash in my case (key is case insensitive)? Another approach is to store it in a hash, but downcase the key before storing and retreiving: irb(main):001:0> h = {"get" => "value_for_get", "post" => "value_for_post"} => {"get"=>"value_for_get", "post"=>"value_for_post"} irb(main):002:0> method = "gEt" => "gEt" irb(main):003:0> h[method.downcase] => "value_for_get" Jesus.