Class: String

Inherits:
Object show all
Defined in:
lib/nutella/core_ext/object/blank.rb,
lib/nutella/core_ext/string/colour.rb,
lib/nutella/core_ext/string/aliases.rb,
lib/nutella/core_ext/string/exclude.rb,
lib/nutella/core_ext/string/heredoc.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/nutella/core_ext/object/blank.rb', line 39

def blank?
  self !~ /[^\s]/
end

#exclude?(str) ⇒ Boolean Also known as: excludes?

The inverse of String#include?.

Parameters:

  • str (String)

    the string to test for exclusion

Returns:

  • (Boolean)

    whether or not the string excludes the substring str



6
7
8
# File 'lib/nutella/core_ext/string/exclude.rb', line 6

def exclude?(str)
  !include? str
end

#heredocString Also known as: format_heredoc, strip_heredoc

Left-aligns a heredoc by finding the least indented line in the string, and removing that amount of leading whitespace from each line.

Examples:

Prints the contents of the heredoc as described on each line

puts <<-EOS.heredoc
  This line would be left-aligned.
  This line too.
      This line would be indented by four spaces.
      As well as this line.
  And back to left-aligned.
EOS

Returns:

  • (String)

    the string with excess leading whitespace stripped



15
16
17
# File 'lib/nutella/core_ext/string/heredoc.rb', line 15

def heredoc
  gsub /^[ \t]{#{scan(/^[ \t]*(?=\S)/).min.size}}/, ""
end