Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Overview
Extend the core String class to include .to_snake
Instance Method Summary collapse
-
#to_snake ⇒ Object
Attempts to convert a string into a formatted_snake_case_string.
Instance Method Details
#to_snake ⇒ Object
Attempts to convert a string into a formatted_snake_case_string
6 7 8 9 10 11 |
# File 'lib/string.rb', line 6 def to_snake gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |