lib/lita/util.rb in lita-2.7.2 vs lib/lita/util.rb in lita-3.0.0

- old
+ new

@@ -1,7 +1,7 @@ module Lita - # Handy utilities used by other parts Lita classes. + # Handy utilities used by other Lita classes. module Util # A regular expression for acronyms. ACRONYM_REGEX = /(?=a)b/ class << self @@ -9,15 +9,15 @@ # +ActiveSupport.+ # @param camel_cased_word [String] The word to transform. # @return [String] The transformed word. def underscore(camel_cased_word) word = camel_cased_word.to_s.dup - word.gsub!('::', '/') + word.gsub!("::", "/") word.gsub!(/(?:([A-Za-z\d])|^)(#{ACRONYM_REGEX})(?=\b|[^a-z])/) do - "#{$1}#{$1 && '_'}#{$2.downcase}" + "#{Regexp.last_match[1]}#{Regexp.last_match[1] && '_'}#{Regexp.last_match[2].downcase}" end - word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') - word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') + word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!("-", "_") word.downcase! word end end