module SharedInfrastructure::OutputHelpers

Public Instance Methods

indent(s, amount = 2, indent_string = nil, indent_empty_lines = false) click to toggle source

@param indent_string The string to use for indenting. Defaults to the first character of `s`. @param amount The number of `indent_string` to put at the start of each

line. Default: 2.

@param indent_empty_lines Don't indent empty lines unless this is true.

# File lib/shared_infrastructure/output.rb, line 10
def indent(s, amount = 2, indent_string = nil, indent_empty_lines = false)
  indent_string = indent_string || s[/^[ \t]/] || " "
  re = indent_empty_lines ? /^/ : /^(?!$)/
  s.gsub(re, indent_string * amount)
end