Class: String

Inherits:
Object show all
Defined in:
dev-cmd/irb.rb,
extend/blank.rb

Direct Known Subclasses

Cask::DSL::Version

Constant Summary collapse

BLANK_RE =
/\A[[:space:]]*\z/.freeze
ENCODED_BLANKS_ =
T.let(Hash.new do |h, enc|
  h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
end, T::Hash[Encoding, Regexp])

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

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

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
163
164
# File 'extend/blank.rb', line 154

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
      T.must(ENCODED_BLANKS_[encoding]).match?(self)
    end
end

#c(config: nil) ⇒ Object



14
15
16
# File 'dev-cmd/irb.rb', line 14

def c(config: nil)
  Cask::CaskLoader.load(self, config: config)
end

#f(*args) ⇒ Object



9
10
11
12
# File 'dev-cmd/irb.rb', line 9

def f(*args)
  require "formula"
  Formulary.factory(self, *args)
end

#present?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'extend/blank.rb', line 167

def present? # :nodoc:
  !blank?
end