Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rubocop/core_ext/string.rb
Overview
Extensions to the core String class
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Checks whether a string is blank.
-
#strip_indent ⇒ Object
The method strips the whitespace preceding the base indentation.
Instance Method Details
#blank? ⇒ Boolean
Checks whether a string is blank. A string is considered blank if it is either empty or contains only whitespace characters.
19 20 21 |
# File 'lib/rubocop/core_ext/string.rb', line 19 def blank? empty? || strip.empty? end |
#strip_indent ⇒ Object
TODO:
Replace call sites with squiggly heredocs when required Ruby version is >= 2.3.0
The method strips the whitespace preceding the base indentation. Useful for HEREDOCs and other multi-line strings.
41 42 43 44 45 |
# 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 |