class String
Extensions to the core String
class
Public Instance Methods
blank?()
click to toggle source
Checks whether a string is blank. A string is considered blank if it is either empty or contains only whitespace characters.
@return [Boolean] true is the string is blank, false otherwise
@example
''.blank? #=> true
@example
' '.blank? #=> true
@example
' test'.blank? #=> false
# File lib/rubocop/core_ext/string.rb, line 19 def blank? empty? || strip.empty? end
strip_indent()
click to toggle source
The method strips the whitespace preceding the base indentation. Useful for HEREDOCs and other multi-line strings.
@example
code = <<~END def test some_method other_method end END #=> "def\n some_method\n \nother_method\nend"
@todo Replace call sites with squiggly heredocs when required Ruby
version is >= 2.3.0
# File lib/rubocop/core_ext/string.rb, line 41 def strip_indent leading_space = scan(/^[ \t]*(?=\S)/).min indent = leading_space ? leading_space.size : 0 gsub(/^[ \t]{#{indent}}/, '') end