Module: Groundskeeper::StringUtils

Defined in:
lib/groundskeeper/string_utils.rb

Overview

Helpers for strings.

Class Method Summary collapse

Class Method Details

.underscore(word) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/groundskeeper/string_utils.rb', line 6

def self.underscore(word)
  return "" unless word.respond_to?(:gsub)

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