Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/patches/string.rb
Overview
rubocop:disable Style/OptionalBooleanParameter, Lint/UnderscorePrefixedVariableName
Instance Method Summary collapse
-
#indent(amount, indent_string = nil, indent_empty_lines = false) ⇒ Object
Copied from Rails.
-
#indent!(amount, indent_string = nil, indent_empty_lines = false) ⇒ Object
Copied from Rails.
-
#pluralize ⇒ Object
Covers only simple cases and used for pluralizing controlplane template kinds (‘gvc`, `secret`, `policy`, etc.).
-
#underscore ⇒ Object
Copied from Rails.
- #unindent ⇒ Object
Instance Method Details
#indent(amount, indent_string = nil, indent_empty_lines = false) ⇒ Object
Copied from Rails
6 7 8 |
# File 'lib/patches/string.rb', line 6 def indent(amount, indent_string = nil, indent_empty_lines = false) dup.tap { |_| _.indent!(amount, indent_string, indent_empty_lines) } end |
#indent!(amount, indent_string = nil, indent_empty_lines = false) ⇒ Object
Copied from Rails
11 12 13 14 15 |
# File 'lib/patches/string.rb', line 11 def indent!(amount, indent_string = nil, indent_empty_lines = false) indent_string = indent_string || self[/^[ \t]/] || " " re = indent_empty_lines ? /^/ : /^(?!$)/ gsub!(re, indent_string * amount) end |
#pluralize ⇒ Object
Covers only simple cases and used for pluralizing controlplane template kinds (‘gvc`, `secret`, `policy`, etc.)
27 28 29 30 31 32 |
# File 'lib/patches/string.rb', line 27 def pluralize return self if empty? return "#{self[...-1]}ies" if end_with?("y") "#{self}s" end |
#underscore ⇒ Object
Copied from Rails
22 23 24 |
# File 'lib/patches/string.rb', line 22 def underscore gsub("::", "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr("-", "_").downcase end |
#unindent ⇒ Object
17 18 19 |
# File 'lib/patches/string.rb', line 17 def unindent gsub(/^#{scan(/^[ \t]+(?=\S)/).min}/, "") end |