Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_additions.rb
Instance Method Summary collapse
Instance Method Details
#camel_case ⇒ Object
11 12 13 |
# File 'lib/string_additions.rb', line 11 def camel_case @camel_case ||= self.underscore.capitalize.gsub( /([A-Z])([A-Z]+)/ ) { "#{$1}#{$2.downcase}" }.gsub( /_(.)/ ) { $1.upcase } end |
#underscore ⇒ Object
7 8 9 |
# File 'lib/string_additions.rb', line 7 def underscore @underscore ||= self.gsub( /([A-Z]+)([A-Z][a-z])/, '\1_\2' ).gsub( /([a-z\d])([A-Z])/, '\1_\2' ).gsub( /\s\s*/, '_' ).downcase end |