Class: String

Inherits:
Object show all
Defined in:
lib/dm-core/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#compress_lines(spaced = true) ⇒ String

Replace sequences of whitespace (including newlines) with either a single space or remove them entirely (according to param spaced)

<<QUERY.compress_lines
  SELECT name
  FROM users
QUERY => "SELECT name FROM users"


18
19
20
# File 'lib/dm-core/core_ext/string.rb', line 18

def compress_lines(spaced = true)
  split($/).map { |line| line.strip }.join(spaced ? ' ' : '')
end