class String

Public Instance Methods

camelize(uppercase_first_letter = true) click to toggle source

apidock.com/rails/String/camelize

# File lib/core_ext/string.rb, line 5
def camelize(uppercase_first_letter = true)
  string = self
  string = if uppercase_first_letter
             string.sub(/^[a-z\d]*/) { $&.capitalize }
           else
             string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
           end
  string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end
titleize() click to toggle source

stackoverflow.com/a/27737214

# File lib/core_ext/string.rb, line 16
def titleize
  split(' ').map(&:capitalize).join(' ')
end