Module: Nori::CoreExt::String

Defined in:
lib/nori/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#snakecaseObject

Returns the String in snake_case.



6
7
8
9
10
11
12
13
14
15
# File 'lib/nori/core_ext/string.rb', line 6

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