Class: String

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

Instance Method Summary collapse

Instance Method Details

#indent(n, c = ' ') ⇒ Object



44
45
46
47
48
49
50
# File 'lib/courtier/core_ext.rb', line 44

def indent(n, c=' ')
  if n >= 0
    gsub(/^/, c * n)
  else
    gsub(/^#{Regexp.escape(c)}{0,#{-n}}/, "")
  end
end

#tabto(n) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/courtier/core_ext.rb', line 36

def tabto(n)
  if self =~ /^( *)\S/
    indent(n - $1.length)
  else
    self
  end
end