On 2006.01.07 05:05, Gregory Seidman wrote:
> So I understand that a hash can use keys of any type, not just string (or
> symbol), but there are occasions when I have a hash that has been populated
> with string keys whose values I would like to access case-insensitively. Is
> there a setting or something? Do I have to write a wrapper to deal with it?
If you always access that particular Hash case-insensitively, then
the simplest solution would be to filter input to it:
@hash[key.downcase] = value
If, on the other hand, you alter between sensitive and insensitive,
you would filter the output instead
# (Naively)
nil unless @hash.keys.find {|k| key.downcase == k.downcase}
@hash[key]
If you need to, you could encapsulate this behaviour in a subclass.
> --Greg
E