Module: FastUnderscore::AcronymUnderscoreRegex
- Defined in:
- lib/fast_underscore/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
#underscore(string) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fast_underscore/acronym_underscore_regex.rb', line 7 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 |