Method: ActiveSupport::Inflector#camelize

Defined in:
lib/jinx/active_support/inflector.rb

#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object

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"


178
179
180
181
182
183
184
185
186
# File 'lib/jinx/active_support/inflector.rb', line 178

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
    # FL - fixed bug: String doesn't have a first method
    #lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
    lower_case_and_underscored_word[0, 1].downcase + camelize(lower_case_and_underscored_word)[1..-1]
  end
end