module ActiveSupport::Inflector
def camelize(term, uppercase_first_letter = true)
#underscore, though there are cases where that does not hold:
As a rule of thumb you can think of +camelize+ as the inverse of
camelize('active_model/errors', false) # => "activeModel::Errors"
camelize('active_model/errors') # => "ActiveModel::Errors"
camelize('active_model', false) # => "activeModel"
camelize('active_model') # => "ActiveModel"
paths to namespaces.
Also converts '/' to '::' which is useful for converting
lowerCamelCase.
If the +uppercase_first_letter+ parameter is set to false, then produces
Converts strings to UpperCamelCase.
def camelize(term, uppercase_first_letter = true) string = term.to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { |match| inflections.acronyms[match] || match.capitalize } else string = string.sub(inflections.acronyms_camelize_regex) { |match| match.downcase } end string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" } string.gsub!("/", "::") string end