Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/array.rb

Overview

Removes common indentation from an array of strings

Instance Method Summary collapse

Instance Method Details

#remove_indentObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/array.rb', line 3

def remove_indent
  lines_with_indent = self.select do |line|
    line.size > 0
  end
  indents = lines_with_indent.map do |line|
    match = line.match(/^( +)([^ ]|$)+/)
    match ? match[1].size : 0
  end
  indent = indents.min
  self.map do |line|
    line[indent..-1]
  end
end