Module: Evoke::Inflections::Camelize
- Defined in:
- lib/evoke/inflections/camelize.rb
Overview
String inflections for converting to CamelCase.
Camelizing a string takes all the compound words separated by an underscore and combines them together, capitalizing the first letter of each word. It also converts ‘/’ to ‘::’. For example “hello_world” is camelized to “HelloWorld”, and “hello/world” is camelized to “Hello::World”.
Instance Method Summary collapse
-
#camelize ⇒ String
Converts a string to CamelCase.
-
#camelize! ⇒ String
Replaces the existing String instance with a CamelCase string.
Instance Method Details
#camelize ⇒ String
Converts a string to CamelCase. It also converts ‘/’ to ‘::’.
17 18 19 20 21 22 23 |
# File 'lib/evoke/inflections/camelize.rb', line 17 def camelize dup.tap do |s| s.capitalize! s.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" } s.gsub!('/', '::') end end |
#camelize! ⇒ String
Replaces the existing String instance with a CamelCase string.
34 35 36 |
# File 'lib/evoke/inflections/camelize.rb', line 34 def camelize! replace(camelize) end |