Class: String
- Inherits:
-
Object
- Object
- String
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/core_ext/string.rb
Overview
typed: strict frozen_string_literal: true
Instance Method Summary collapse
Instance Method Details
#underscore ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tapioca/core_ext/string.rb', line 8 def underscore return self unless /[A-Z-]|::/.match?(self) word = to_s.gsub("::", "/") 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 |