case insensitive inclusion validation

Is there a use case where you wouldn’t just do something like…

validates :numbers, inclusion: { in: [‘one’, ‘two’] }

def numbers



i.e. Is there a particular reason why you still want the values to be stored/presented with potentially different cases, but want the validation to be case insensitive?

I couldn’t think of a lot of these use cases, so I have reservations on putting this in core. Plus it seems quite easy to implement yourself?

Also, how do you plan to implement this? It seems like your only option is to call .to_a on the in/within option into an Array, and then call .map(&:downcase) on each element. This has several problems:

  1. In extreme cases, this might be very inefficient. (e.g. When the input is a large Range)

  2. What if the option cannot be turned into an Array at all? I know in the docs it says it has to be at least an Enumerable, but the code only requires the object to respond to #include?. This wouldn’t work when I do something like:

class SimplePasswordChecker

def include?( password )

# Check length of password

# Check against some dictionary

# Return true if the password is to simple...



validates :password, exclusion: { in:, case_insensitive: true }, on: :create

  1. What if the options in the array are not strings? Do you call .to_s and then .downcase ?

Given the a) the use case seems quite rare, b) it’s easy to implement yourself, c) the solution can’t be very generic/robust against all input values, my vote is -1.

There’s also the little issue of the world not all using only English. A full Unicode-aware case insensitivity is even more inefficient than a regular ascii-only one… but in practice might be required in just as many cases as an ascii one…