Module: Camelize

Included in:
Kernel
Defined in:
lib/core/utils/extensions/string/camelize.rb

Overview

Adds some useful methods to the String class

Instance Method Summary collapse

Instance Method Details

#camelizeString

Convert a string to camel case format

Returns:

  • (String)

    the camel case formatted string



5
6
7
8
9
10
# File 'lib/core/utils/extensions/string/camelize.rb', line 5

def camelize
  words = split(/(?<=[a-z])(?=[A-Z])|[-_\s]+/) # Split at lowercase-to-uppercase transitions or explicit separators
          .map(&:downcase) # Convert everything to lowercase for consistency

  words.map.with_index { |word, index| index.zero? ? word : word.capitalize }.join
end