Method: Kennel::Utils.snake_case

Defined in:
lib/kennel/utils.rb

.snake_case(string) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/kennel/utils.rb', line 17

def snake_case(string)
  string
    .gsub(/::/, "_") # Foo::Bar -> foo_bar
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # FOOBar -> foo_bar
    .gsub(/([a-z\d])([A-Z])/, '\1_\2') # fooBar -> foo_bar
    .downcase
end