class String

Public Instance Methods

camelize() click to toggle source
# File lib/frenchy/core_ext.rb, line 11
def camelize
  dup.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end
constantize() click to toggle source
# File lib/frenchy/core_ext.rb, line 15
def constantize
  names = self.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end

  constant
end
underscore() click to toggle source
# File lib/frenchy/core_ext.rb, line 27
def underscore
  dup.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end