Include Case-Insensitive

Is there a way to make include? case insensitive?

Sort of. You can’t expect to change ruby’s constant system to be
insensitive, but if you’re OK with passing in strings, this might
work:

class Module
def include_insensitive(*args)
args.each do |m|
include(const_get(Module.constants.grep(/^#{m}$/i).first))
end
self
end
end

module M
def im_in_m
:hi
end
end

class C
include_insensitive “m”
end

C.new.im_in_m #=> :hi

On Mar 26, 2:29 am, Sam K. [email protected]

Sam K. wrote:

Is there a way to make include? case insensitive?

You can also use the downcase() function :

“Hello World”.downcase.include?(“hello”) => true