Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/chgk_rating/utils/snakecase.rb
Overview
Initial code taken from Facets gem by Rubyworks github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
Instance Method Summary collapse
-
#snakecase_upcase ⇒ Object
Underscore a string such that camelcase, dashes and spaces are replaced by underscores.
Instance Method Details
#snakecase_upcase ⇒ Object
Underscore a string such that camelcase, dashes and spaces are replaced by underscores.
9 10 11 12 13 14 15 16 17 |
# File 'lib/chgk_rating/utils/snakecase.rb', line 9 def snakecase_upcase split('::').last. gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr('-', '_'). gsub(/\s/, '_'). gsub(/__+/, '_'). upcase end |