Module: SinatraResource::Utility

Defined in:
lib/utility.rb

Class Method Summary collapse

Class Method Details

.underscore(camel_cased_word) ⇒ String

The reverse of camelize. Makes an underscored, lowercase form from the expression in the string.

Example:

"SourceGroup".underscore # => "source_group"

(This method was adapted from ActiveSupport 2.3.5)

Parameters:

  • camel_cased_word (String)

Returns:

  • (String)


16
17
18
19
20
21
22
# File 'lib/utility.rb', line 16

def self.underscore(camel_cased_word)
  camel_cased_word.to_s.
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z\d])([A-Z])/, '\1_\2').
    tr("-", "_").
    downcase
end