Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/extension.rb
Instance Method Summary collapse
-
#camel_case ⇒ Object
returns camel_case representation of string.
-
#snake_case ⇒ Object
returns snake_case representation of string.
Instance Method Details
#camel_case ⇒ Object
returns camel_case representation of string
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/extension.rb', line 8 def camel_case if self.include? '_' self.split('_').map { |e| e.capitalize }.join else unless self =~ (/^[A-Z]/) self.capitalize else self end end end |
#snake_case ⇒ Object
returns snake_case representation of string
3 4 5 |
# File 'lib/extension.rb', line 3 def snake_case gsub(/([a-z])([A-Z0-9])/, '\1_\2').downcase end |