Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/testytest.rb
Instance Method Summary collapse
Instance Method Details
#dedent ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/testytest.rb', line 4 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 |