Sha256: 6dabd18691ee97588868f45f7f6923b270e10e9ef74079414dcccee8d497840e

Contents?: true

Size: 716 Bytes

Versions: 275

Compression:

Stored size: 716 Bytes

Contents

class String
  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
  
  def line_of(index)
    self[0...index].count("\n") + 1
  end

  unless method_defined?(:blank?)
    def blank?
      self == ""
    end
  end

  # The following methods are lifted from Facets 2.0.2
  def tabto(n)
    if self =~ /^( *)\S/
      indent(n - $1.length)
    else
      self
    end
  end

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

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

Version data entries

275 entries across 234 versions & 24 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/treetop-1.4.10/lib/treetop/ruby_extensions/string.rb
classiccms-0.7.4 vendor/bundle/gems/treetop-1.4.10/lib/treetop/ruby_extensions/string.rb
classiccms-0.7.3 vendor/bundle/gems/treetop-1.4.10/lib/treetop/ruby_extensions/string.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/treetop-1.4.12/lib/treetop/ruby_extensions/string.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/treetop-1.4.12/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.1 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.10 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.13 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.16 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.2 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.3 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.4 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.5 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.6 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.8 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.0.9 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.1.0 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.1.1 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.1.10 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
cloudhead-less-1.1.11 lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb