From: "Jesús Gabriel y Galán" Date: 2008-04-16T06:40:28+09:00 Subject: Re: Hash or bidimensional Array when key is case insensitive On Tue, Apr 15, 2008 at 11:27 PM, Iñaki Baz Castillo wrote: > El Martes, 15 de Abril de 2008, Stefan Rusterholz escribió: > > > Iñaki Baz Castillo wrote: > > > And if I use a Hash I'll do the same: > > > > > > method = params_hash.find { |param| param[0] =~ /^method$/i }[1] > > > > Use a hash and lowercase the keys. If you need to preserve the original > > casing, do that in the value, e.g. like this: {key.lowercase => [key, > > value], ...} > > Ah ok, it's a good idea :) Hey, now I got your requirements !! Please ignore my other post... > > Another approach would be a special Key class which is like String but > > has #hash and #eql? redefined to work as if the String was lowercased. > > Thanks but I don't understnad this point. Do you mean extending the Hash > class? I don't think so since there is not any Key class. Could you please > explain in more detail you suggestion? What he means is that instead of lowercasing the key before inserting in the hash, you create a Key class in a way that the hash will think two keys are the same if they have the same string ignoring case. Something like (not tested): class Key attr_reader :key def initialize key @key = key end def hash @key.downcase.hash end def eql? other @key.downcase.eql? other.downcase end end and then you populate the hash as: h[Key.new(method)] = [method, values_for_method] this way you locate the entry in the hash ignoring case and have the original value in the value of the hash. Hope I've explained myself... Jesus.