Module: FastUnderscore::ActiveSupportInflectorPatch

Defined in:
lib/fast_underscore.rb

Overview

Override ActiveSupport::Inflector::underscore to use FastUnderscore::underscore for ActiveSupport >= 5.2.0.

Instance Method Summary collapse

Instance Method Details

#underscore(string) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/fast_underscore.rb', line 32

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

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

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

  FastUnderscore.underscore(response)
end