Module: Underscorable
- Defined in:
- lib/underscorable.rb
Instance Method Summary collapse
-
#underscore ⇒ Object
Port from activesupport-4.2.7.1/lib/active_support/inflector/methods.rb.
Instance Method Details
#underscore ⇒ Object
Port from activesupport-4.2.7.1/lib/active_support/inflector/methods.rb
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/underscorable.rb', line 5 def underscore return self unless self =~ /[A-Z-]|::/ word = to_s.gsub('::', '/') word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) do "#{::Regexp.last_match(1) && '_'}#{::Regexp.last_match(2).downcase}" end 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 |