Method: ActiveSupport::Inflector#underscore

Defined in:
lib/jinx/active_support/inflector.rb

#underscore(camel_cased_word) ⇒ Object

The reverse of camelize. Makes an underscored, lowercase form from the expression in the string.

Changes ‘::’ to ‘/’ to convert namespaces to paths.

Examples:

"ActiveRecord".underscore         #=>"active_record"
"ActiveRecord::Errors".underscore #=>active_record/errors


208
209
210
211
212
213
214
# File 'lib/jinx/active_support/inflector.rb', line 208

def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end