Class: String

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

Instance Method Summary collapse

Instance Method Details

#margin(n = 0) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rod/string_ex.rb', line 2

def margin(n=0)
  #d = /\A.*\n\s*(.)/.match( self )[1]
  #d = /\A\s*(.)/.match( self)[1] unless d
  d = ((/\A.*\n\s*(.)/.match(self)) ||
      (/\A\s*(.)/.match(self)))[1]
  return '' unless d
  if n == 0
    gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '')
  else
    gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n)
  end
end