Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/shelter.rb
Overview
Extend String class with camelize
Instance Method Summary collapse
Instance Method Details
#camelize(uppercase_first_letter = true) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shelter.rb', line 13 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(%r{(?:_|(/))([a-z\d]*)}) do "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" end.gsub('/', '::') end |