Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#snake_case(seperator = '/') ⇒ Object



12
13
14
15
16
17
18
# File 'lib/core_ext/string.rb', line 12

def snake_case(seperator = '/')
  string = seperator == '::' ? dup : gsub(/::/, '/')
  string.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  string.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  string.tr!("-", "_")
  string.downcase
end