class Dry::Inflector

def underscore(input)

Other tags:
    Since: - 0.1.0

Returns:
  • (String) - the underscored string

Parameters:
  • input (String, Symbol) -- the input
def underscore(input)
  input = input.to_s.gsub("::", "/")
  input.gsub!(inflections.acronyms.regex) do
    m1 = Regexp.last_match(1)
    m2 = Regexp.last_match(2)
    "#{m1 ? "_" : ""}#{m2.downcase}"
  end
  input.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  input.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  input.tr!("-", "_")
  input.downcase!
  input
end