Class: String

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

Instance Method Summary collapse

Instance Method Details

#unindentObject



2
3
4
5
# File 'lib/unindent.rb', line 2

def unindent
  indent = self.split("\n").select {|line| !line.strip.empty? }.map {|line| line.index(/[^\s]/) }.compact.min || 0
  self.gsub(/^[[:blank:]]{#{indent}}/, '')
end

#unindent!Object



6
7
8
# File 'lib/unindent.rb', line 6

def unindent!
  self.replace(self.unindent)
end