Sha256: 072883b277a7f2827e4376693ac55958ed51ebeeeff31bd52b4c18f72343e9f5

Contents?: true

Size: 973 Bytes

Versions: 4

Compression:

Stored size: 973 Bytes

Contents

class String
  def constantize()
    names = self.split('::')
    names.shift if names.empty? || names.first.empty?

    names.inject(Object) { |obj, name|
      obj = obj.const_defined?(name) ? obj.const_get(name) : obj.const_missing(name)
    }
  end

  def camelize()
    self.dup.camelize!
  end

  def camelize!()
    self.replace(self.split(/[\W_]+/).collect(&:capitalize).join)
  end

  def underscore!()
    self.tap {|word|
      word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
      word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
      word.tr!("-", "_")
      word.downcase!
    }
  end

  def titleize!
    self.tap { |title|
      title.replace(title.split(/\b/).collect(&:capitalize).join)
    }
  end
  alias :titlize! :titleize!

  def titleize
    self.dup.titleize!
  end
  alias :titlize :titleize

  def underscore()
    self.dup.underscore!
  end

  def dasherize!()
    self.underscore!.gsub!(/_/, '-')
  end

  def dasherize()
    self.dup.dasherize!
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
githooker-0.2.12 lib/githooker/core_ext/string/inflections.rb
githooker-0.2.11 lib/githooker/core_ext/string/inflections.rb
githooker-0.2.10 lib/githooker/core_ext/string/inflections.rb
githooker-0.2.0 lib/githooker/core_ext/string/inflections.rb