Module: Underscorable

Included in:
Clashinator::Base
Defined in:
lib/clashinator/util/underscore.rb

Overview

module to convert camelcase to underscore

Instance Method Summary collapse

Instance Method Details

#to_underscore(name) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/clashinator/util/underscore.rb', line 3

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