Sha256: ca13b08ab26482302a0dd3500c88392ab8c8293a1cc5d1a7ce81bcc75372247e
Contents?: true
Size: 644 Bytes
Versions: 1
Compression:
Stored size: 644 Bytes
Contents
# frozen_string_literal: true module FastUnderscore # Uses ActiveSupport's `acronym_underscore_regex` method for replacing # acronyms within strings that need to be underscored. module AcronymUnderscoreRegex 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 end class << ActiveSupport::Inflector alias as_underscore underscore prepend AcronymUnderscoreRegex end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fast_underscore-0.2.0 | lib/fast_underscore/ext/acronym_underscore_regex.rb |