class String

rubocop:disable all

Public Instance Methods

blank?() click to toggle source

A string is blank if it's empty or contains whitespaces only:

''.blank?       # => true
'   '.blank?    # => true
"\t\n\r".blank? # => true
' blah '.blank? # => false

Unicode whitespace is supported:

"\u00a0".blank? # => true

@return [true, false]

# File lib/activesupport/blank.rb, line 120
def blank?
  # The regexp that matches blank strings is expensive. For the case of empty
  # strings we can speed up this method (~3.5x) with an empty? call. The
  # penalty for the rest of strings is marginal.
  empty? ||
    begin
      BLANK_RE.match?(self)
    rescue Encoding::CompatibilityError
      false
    end
end
camelize() click to toggle source

Converts strings to UpperCamelCase.

Also converts '/' to '::' which is useful for converting paths to namespaces.

camelize('active_model')                # => "ActiveModel"
camelize('active_model/errors')         # => "ActiveModel::Errors"

Modified copy of ActiveSupport::Inflector.camelize. Since I did not need those features, I removed the handling of the :lower parameter and the handling of acronyms. github.com/rails/rails/blob/v6.1.3.1/activesupport/lib/active_support/inflector/methods.rb

# File lib/activesupport/camelize.rb, line 17
def camelize
  string = to_s
  string = string.sub(/^[a-z\d]*/) { |match| match.capitalize! || match }
  string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
    word        = Regexp.last_match(2)
    substituted = word.capitalize! || word
    Regexp.last_match(1) ? "::#{substituted}" : substituted
  end
  string
end
constantize() click to toggle source
# File lib/activesupport/camelize.rb, line 28
def constantize
  Object.const_get(self)
end