From: "Iñaki Baz Castillo" Date: 2008-04-16T06:48:16+09:00 Subject: Re: Hash or bidimensional Array when key is case insensitive El Martes, 15 de Abril de 2008, Jesús Gabriel y Galán escribió: > > 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... Sure, it's cool :) Thanks a lot to both. -- Iñaki Baz Castillo