Class: Inum::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/inum/utils.rb

Overview

Utils of Inum.

Class Method Summary collapse

Class Method Details

.underscore(camel_cased_word) ⇒ String

convert a camel cased word to a underscore word.

Parameters:

  • camel_cased_word (String, Symbol)

    camel cased word.

Returns:

  • (String)

    underscore word.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/inum/utils.rb', line 9

def self.underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup

  word.gsub!('::', '.')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!('-', '_')

  word.downcase!

  word
end