Method: String#underscore

Defined in:
lib/yard/core_ext/string.rb

#underscoreString

Separates capital letters following lower case letters by an underscore and returns the entire string in lower case

Examples:

"FooBar".underscore # => "foo_bar"
"Foo::Bar".underscore # => "foo/bar"

Returns:

  • (String)

    the underscored lower case string



9
10
11
# File 'lib/yard/core_ext/string.rb', line 9

def underscore
  gsub(/([a-z])([A-Z])/, '\1_\2').downcase.gsub('::', '/')
end