Module: Eco::Data::Strings::SnakeCase

Included in:
Hashes::SnakeCamelIndifferentAccess, Locations::NodeDiff::Accessors::ClassMethods
Defined in:
lib/eco/data/strings/snake_case.rb

Instance Method Summary collapse

Instance Method Details

#snake_case(camel_cased_word) ⇒ Object

From ActiveSupport



7
8
9
10
11
12
13
14
# File 'lib/eco/data/strings/snake_case.rb', line 7

def snake_case(camel_cased_word)
  return camel_cased_word.to_s.dup 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])/, "_")
  word.tr!("-", "_")
  word.downcase!
  word
end