Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/omdbapi/default.rb
Overview
Reopen the String class to add to_snake_case method.
Instance Method Summary collapse
-
#to_snake_case ⇒ String
Convert string to snake case from camel case.
Instance Method Details
#to_snake_case ⇒ String
Convert string to snake case from camel case.
34 35 36 37 38 39 40 |
# File 'lib/omdbapi/default.rb', line 34 def to_snake_case self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |