Module: SharedInfrastructure::OutputHelpers

Defined in:
lib/shared_infrastructure/output.rb

Instance Method Summary collapse

Instance Method Details

#indent(s, amount = 2, indent_string = nil, indent_empty_lines = false) ⇒ Object

first character of ‘s`.

Parameters:

  • indent_string (defaults to: nil)

    The string to use for indenting. Defaults to the

  • amount (defaults to: 2)

    The number of ‘indent_string` to put at the start of each line. Default: 2.

  • indent_empty_lines (defaults to: false)

    Don’t indent empty lines unless this is true.



10
11
12
13
14
# 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