Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/montage/core_ext.rb
Overview
Some simple string extensions to make things easier.
Instance Method Summary collapse
-
#compress_lines ⇒ String
Replace sequences of whitespace (including newlines) with either a single space or remove them entirely (according to param spaced).
-
#unindent ⇒ String
Removes leading whitespace from each line, such as might be added when using a HEREDOC string.
-
#unindent! ⇒ String
Bang version of #unindent.
Instance Method Details
#compress_lines ⇒ 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"
14 15 16 |
# File 'lib/montage/core_ext.rb', line 14 def compress_lines split($/).map { |line| line.strip }.join(' ') end |
#unindent ⇒ String
Removes leading whitespace from each line, such as might be added when using a HEREDOC string.
23 24 25 |
# File 'lib/montage/core_ext.rb', line 23 def unindent (other = dup) and other.unindent! and other end |
#unindent! ⇒ String
Bang version of #unindent.
31 32 33 |
# File 'lib/montage/core_ext.rb', line 31 def unindent! gsub!(/^[ \t]{#{minimum_leading_whitespace}}/, '') end |