class String

Public Instance Methods

blank?() click to toggle source
# File lib/treetop/ruby_extensions/string.rb, line 17
def blank?
  self == ""
end
column_of(index) click to toggle source
# File lib/treetop/ruby_extensions/string.rb, line 2
def column_of(index)
  return 1 if index == 0
  newline_index = rindex("\n", index - 1)
  if newline_index
    index - newline_index
  else
    index + 1
  end
end
indent(n) click to toggle source
# File lib/treetop/ruby_extensions/string.rb, line 31
def indent(n)
  if n >= 0
    gsub(%r^/, ' ' * n)
  else
    gsub(%r^ {0,#{-n}}/, "")
  end
end
line_of(index) click to toggle source
# File lib/treetop/ruby_extensions/string.rb, line 12
def line_of(index)
  self[0...index].count("\n") + 1
end
tabto(n) click to toggle source

The following methods are lifted from Facets 2.0.2

# File lib/treetop/ruby_extensions/string.rb, line 23
def tabto(n)
  if self =~ %r^( *)\S/
    indent(n - $1.length)
  else
    self
  end
end
treetop_camelize() click to toggle source
# File lib/treetop/ruby_extensions/string.rb, line 39
def treetop_camelize
  to_s.gsub(%r\/(.?)/){ "::" + $1.upcase }.gsub(%r(^|_)(.)/){ $2.upcase }
end