class String

Reopen the String class to add to_snake_case method.

Public Instance Methods

to_snake_case() click to toggle source

Convert string to snake case from camel case.

@return [String] @example

"CamelCasedString".to_snake_case # => "camel_cased_string"
# 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