rearmed-rb icon indicating copy to clipboard operation
rearmed-rb copied to clipboard

Add CIHash

Open westonganger opened this issue 3 years ago • 0 comments

################################################## CIHash (Case-Insensitive Hash) - HELPFUL FOR HASH KEY COMPARISONS WHERE WE NEED TO IGNORE CASE ERRORS
class CIHash < HashWithIndifferentAccess
  def [](k)
    if self.has_key?(k)
      return super(k)
    else
      alt_key = self.keys.detect{|x| x.to_s.casecmp?(k) }

      if alt_key
        return super(alt_key)
      else
        return nil;
      end
    end
  end
end

westonganger avatar Aug 19 '21 17:08 westonganger