typecheck
This commit is contained in:
parent
7aab1c2a38
commit
6cfab10e2b
@ -143,11 +143,11 @@ module Utils
|
||||
# `ActiveSupport::Inflector.underscore`
|
||||
sig { params(camel_cased_word: T.any(String, Symbol)).returns(String) }
|
||||
def self.underscore(camel_cased_word)
|
||||
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
|
||||
return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
|
||||
|
||||
word = camel_cased_word.to_s.gsub("::", "/")
|
||||
word.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
|
||||
(::Regexp.last_match(1) || ::Regexp.last_match(2)) << "_"
|
||||
T.must(::Regexp.last_match(1) || ::Regexp.last_match(2)) << "_"
|
||||
end
|
||||
word.tr!("-", "_")
|
||||
word.downcase!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user