Case-insensitive Array#include?

后端 未结 6 1053
小蘑菇
小蘑菇 2020-12-13 12:35

I want to know what\'s the best way to make the String.include? methods ignore case. Currently I\'m doing the following. Any suggestions? Thanks!



        
6条回答
  •  庸人自扰
    2020-12-13 12:52

    For an array, use:

    array.map(&:downcase).include?(string)
    

    Regexps are very slow and should be avoided.

提交回复
热议问题