class String
Extend String
class with camelize
Public Instance Methods
camelize(uppercase_first_letter = true)
click to toggle source
# File lib/shelter.rb 13 def camelize(uppercase_first_letter = true) 14 string = self 15 string = if uppercase_first_letter 16 string.sub(/^[a-z\d]*/) { $&.capitalize } 17 else 18 string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } 19 end 20 string.gsub(%r{(?:_|(/))([a-z\d]*)}) do 21 "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" 22 end.gsub('/', '::') 23 end