Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/adtraction/api/extensions/string.rb
Instance Method Summary collapse
Instance Method Details
#camelize(first_letter = :upper) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/adtraction/api/extensions/string.rb', line 3 def camelize(first_letter = :upper) string = self case first_letter when :upper string = string.sub(/^[a-z\d]*/) { $&.capitalize } when :lower string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } else raise ArgumentError, "Invalid option, use either :upper or :lower." end string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') end |