Class: String

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

Instance Method Summary collapse

Instance Method Details

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



11
12
13
14
15
16
17
# File 'lib/rc/core_ext/string.rb', line 11

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

#tabto(n) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/rc/core_ext/string.rb', line 3

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