Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/treetop/ruby_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/treetop/ruby_extensions/string.rb', line 17

def blank?
  self == ""
end

#column_of(index) ⇒ Object



2
3
4
5
6
7
8
9
10
# 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

#line_of(index) ⇒ Object



12
13
14
# File 'lib/treetop/ruby_extensions/string.rb', line 12

def line_of(index)
  self[0...index].count("\n") + 1
end

#tabto(n) ⇒ Object

The following methods are lifted from Facets 2.0.2



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/treetop/ruby_extensions/string.rb', line 23

def tabto(n)
  if self =~ /^( *)\S/
    # Inlined due to collision with ActiveSupport 4.0: indent(n - $1.length)
    m = n - $1.length
    if m >= 0
      gsub(/^/, ' ' * m)
    else
      gsub(/^ {0,#{-m}}/, "")
    end
  else
    self
  end
end

#treetop_camelizeObject



37
38
39
# File 'lib/treetop/ruby_extensions/string.rb', line 37

def treetop_camelize
  to_s.gsub(/\/(.?)/){ "::" + $1.upcase }.gsub(/(^|_)(.)/){ $2.upcase }
end