Method: String#underscore
- Defined in:
- lib/core_ext.rb
#underscore ⇒ Object
:reek:TooManyStatements
30 31 32 33 34 35 36 |
# File 'lib/core_ext.rb', line 30 def underscore return self unless self =~ /[A-Z-]|::/ 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('-', '_').downcase end |