instance method
camelize
Ruby on Rails 3.0.20
Since v2.2.3Signature
camelize(lower_case_and_underscored_word, first_letter_in_uppercase = 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.
Examples:
"active_record".camelize # => "ActiveRecord" "active_record".camelize(:lower) # => "activeRecord" "active_record/errors".camelize # => "ActiveRecord::Errors" "active_record/errors".camelize(:lower) # => "activeRecord::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
-
lower_case_and_underscored_wordreq -
first_letter_in_uppercaseopt = true
Source
# File activesupport/lib/active_support/inflector/methods.rb, line 28
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
if first_letter_in_uppercase
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
else
lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
end
end
Defined in activesupport/lib/active_support/inflector/methods.rb line 28
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Inflector