Method: String#flush

Defined in:
lib/chef/sugar/core_extensions/string.rb

#flushString

Left-flush a string based off of the number of whitespace characters on the first line. This is especially useful for heredocs when whitespace matters.

Examples:

Remove leading whitespace and flush

"  def method\n    'This is a string!'\n  end\nEOH #=>\"def method\\n  'This is a string!'\\nend\"\n".flush

Returns:



63
64
65
# File 'lib/chef/sugar/core_extensions/string.rb', line 63

def flush
  gsub(/^#{self[/\A\s*/]}/, '').chomp
end