instance method const_regexp

Ruby on Rails 7.1.6

Since v5.2.8.1 Private

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

const_regexp(camel_cased_word)

Mounts a regular expression, returned as a string to ease interpolation, that will match part by part the given constant.

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

Parameters

camel_cased_word req
Source
# File activesupport/lib/active_support/inflector/methods.rb, line 357
      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

Defined in activesupport/lib/active_support/inflector/methods.rb line 357 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Inflector

Type at least 2 characters to search.

↑↓ navigate · open · esc close