module ActiveSupport::Inflector

def const_regexp(camel_cased_word)

const_regexp("::") # => "::"
const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"

that will match part by part the given constant.
Mounts a regular expression, returned as a string to ease interpolation,
def const_regexp(camel_cased_word)
  parts = camel_cased_word.split("::")
  return Regexp.escape(camel_cased_word) if parts.empty?
  last = parts.pop
  parts.reverse!.inject(last) do |acc, part|
    part.empty? ? acc : "#{part}(::#{acc})?"
  end
end