Module: FastUnderscore::AcronymUnderscoreRegex

Defined in:
lib/fast_underscore/ext/acronym_underscore_regex.rb

Overview

Uses ActiveSupport’s ‘acronym_underscore_regex` method for replacing acronyms within strings that need to be underscored.

Instance Method Summary collapse

Instance Method Details

#underscoreObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/fast_underscore/ext/acronym_underscore_regex.rb', line 7

def underscore
  return self unless /[A-Z-]|::/.match?(self)

  response = dup
  acronyms = ActiveSupport::Inflector.inflections.acronyms_underscore_regex

  response.gsub!(acronyms) { "#{$1 && '_'}#{$2.downcase}" }

  FastUnderscore.underscore(response)
end