class String

Public Instance Methods

dedent() click to toggle source
# File lib/mina/String.rb, line 2
def dedent
  lines = split "\n"
  return self if lines.empty?
  indents = lines.map do |line|
    line =~ /\S/ ? (line.start_with?(" ") ? line.match(/^ +/).offset(0)[1] : 0) : nil
  end
  min_indent = indents.compact.min
  return self if min_indent.zero?
  lines.map { |line| line =~ /\S/ ? line.gsub(/^ {#{min_indent}}/, "") : line }.join "\n"
end