Sha256: 2c15d4e00447eb52cbc9d9021ca54fb4327e5c8dd93d4198e3af63688a155f5d
Contents?: true
Size: 901 Bytes
Versions: 4
Compression:
Stored size: 901 Bytes
Contents
# -*- coding: utf-8 -*- module Rnfse class String < ::String def self.camelize(term, uppercase_first_letter = true) string = term.to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { $&.capitalize } else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } end string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { $2.capitalize } string.gsub!('/', '::') string end def camelize self.class.camelize(self) end def self.underscore(term) word = term.to_s.gsub('::', '/') word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) #{ "#{$1}#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end def underscore self.class.underscore(self) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rnfse-0.3.0 | lib/rnfse/string.rb |
rnfse-0.0.3 | lib/rnfse/string.rb |
rnfse-0.0.2 | lib/rnfse/string.rb |
rnfse-0.0.1 | lib/rnfse/string.rb |