Sha256: ddf61cba4446f35afa7cefe037d7fcbc965db4361507fdc1066c508c92fa643a
Contents?: true
Size: 1.32 KB
Versions: 5
Compression:
Stored size: 1.32 KB
Contents
# sqa/lib/patches/string.rb ##################################################################### ### ## File: string.rb ## Desc: Monkey to the String class. # class String ################################## ## Convert CamelCase to camel_case def to_underscore self.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') .gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("- ", "_") .downcase end alias :to_snakecase :to_underscore alias :snakecase :to_underscore alias :snake_case :to_underscore alias :underscore :to_underscore ################################## ## Convert camel_case to CamelCase def to_camelcase self.gsub(/\/(.?)/) { "::" + $1.upcase } .gsub(/(^|_)(.)/) { $2.upcase } end alias :camelcase :to_camelcase alias :camelize :to_camelcase ################################## ## Convert "CamelCase" into CamelCase def to_constant names = self.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| if '1.9' == RUBY_VERSION[0,3] constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) else constant = constant.const_get(name) || constant.const_missing(name) end end constant end alias :constantize :to_constant end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
sqa-0.0.24 | lib/patches/string.rb |
sqa-0.0.22 | lib/patches/string.rb |
sqa-0.0.21 | lib/patches/string.rb |
sqa-0.0.20 | lib/patches/string.rb |
sqa-0.0.19 | lib/patches/string.rb |