Module: Strings::Fold
- Defined in:
- lib/strings/fold.rb
Constant Summary collapse
- LINE_BREAK =
"(\r\n+|\r+|\n+|\t+)".freeze
Class Method Summary collapse
-
.fold(text, separator = LINE_BREAK) ⇒ String
Fold a multiline text into a single line string.
Class Method Details
.fold(text, separator = LINE_BREAK) ⇒ String
Fold a multiline text into a single line string
20 21 22 23 24 |
# File 'lib/strings/fold.rb', line 20 def fold(text, separator = LINE_BREAK) text.gsub(/([ ]+)#{separator}/, "\\1") .gsub(/#{separator}(?<space>[ ]+)/, "\\k<space>") .gsub(/#{separator}/, " ") end |