Re: Hash or bidimensional Array when key is case insensitive?
- From: Jesús Gabriel y Galán <jgabrielygalan@xxxxxxxxx>
- Date: Tue, 15 Apr 2008 13:06:38 -0500
On Tue, Apr 15, 2008 at 6:31 PM, Iñaki Baz Castillo <ibc@xxxxxxxxx> 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.
.
- Follow-Ups:
- Re: Hash or bidimensional Array when key is case insensitive?
- From: Iñaki Baz Castillo
- Re: Hash or bidimensional Array when key is case insensitive?
- References:
- Hash or bidimensional Array when key is case insensitive?
- From: Iñaki Baz Castillo
- Hash or bidimensional Array when key is case insensitive?
- Prev by Date: Re: Ruport 1.6 and Murdoch 1.0
- Next by Date: Re: Question regarding mechanize lib
- Previous by thread: Re: Hash or bidimensional Array when key is case insensitive
- Next by thread: Re: Hash or bidimensional Array when key is case insensitive?
- Index(es):
Relevant Pages
|
|