Method: String#underscore
- Defined in:
- lib/sequel/extensions/inflector.rb
#underscore ⇒ Object
The reverse of camelize. Makes an underscored form from the expression in the string. Also changes ‘::’ to ‘/’ to convert namespaces to paths.
Examples
"ActiveRecord".underscore #=> "active_record"
"ActiveRecord::Errors".underscore #=> active_record/errors
280 281 282 283 |
# File 'lib/sequel/extensions/inflector.rb', line 280 def underscore gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase end |