class String
Extend the core String
class to include ‘.to_snake`
Public Instance Methods
to_snake()
click to toggle source
Attempts to convert a string into a formatted_snake_case_string
# 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