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
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/underscorable.rb', line 3 def underscore return self unless self =~ /[A-Z-]|::/ word = self.to_s.gsub(/::/, '/') word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" } 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 |