instance method
camelize
Ruby on Rails 4.0.13
Since v2.2.3Signature
camelize(term, uppercase_first_letter = true)
By default, camelize converts strings to UpperCamelCase. If the argument to camelize is set to :lower then camelize produces lowerCamelCase.
camelize will also convert ‘/’ to ‘::’ which is useful for converting paths to namespaces.
'active_model'.camelize # => "ActiveModel" 'active_model'.camelize(:lower) # => "activeModel" 'active_model/errors'.camelize # => "ActiveModel::Errors" 'active_model/errors'.camelize(:lower) # => "activeModel::Errors"
As a rule of thumb you can think of camelize as the inverse of underscore, though there are cases where that does not hold:
'SSLError'.underscore.camelize # => "SslError"
Parameters
-
termreq -
uppercase_first_letteropt = true
Source
# File activesupport/lib/active_support/inflector/methods.rb, line 69
def camelize(term, uppercase_first_letter = true)
string = term.to_s
if uppercase_first_letter
string = string.sub(/^[a-z\d]*/) { inflections.acronyms[$&] || $&.capitalize }
else
string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { $&.downcase }
end
string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }.gsub('/', '::')
end
Defined in activesupport/lib/active_support/inflector/methods.rb line 69
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Inflector