Module: ActiveSupport::CoreExtensions::String::Inflections
- Included in:
- String
- Defined in:
- lib/active_support/core_ext/string/inflections.rb
Overview
Makes it possible to do “posts”.singularize that returns “post” and “MegaCoolClass”.underscore that returns “mega_cool_class”.
Instance Method Summary collapse
- #camelize ⇒ Object (also: #camelcase)
- #classify ⇒ Object
- #constantize ⇒ Object
- #demodulize ⇒ Object
- #foreign_key(separate_class_name_and_id_with_underscore = true) ⇒ Object
-
#humanize ⇒ Object
Capitalizes the first word and turns underscores into spaces and strips _id, so “employee_salary” becomes “Employee salary” and “author_id” becomes “Author”.
- #pluralize ⇒ Object
- #singularize ⇒ Object
- #tableize ⇒ Object
- #titleize ⇒ Object (also: #titlecase)
- #underscore ⇒ Object
Instance Method Details
#camelize ⇒ Object Also known as: camelcase
15 16 17 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 15 def camelize Inflector.camelize(self) end |
#classify ⇒ Object
37 38 39 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 37 def classify Inflector.classify(self) end |
#constantize ⇒ Object
51 52 53 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 51 def constantize Inflector.constantize(self) end |
#demodulize ⇒ Object
29 30 31 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 29 def demodulize Inflector.demodulize(self) end |
#foreign_key(separate_class_name_and_id_with_underscore = true) ⇒ Object
47 48 49 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 47 def foreign_key(separate_class_name_and_id_with_underscore = true) Inflector.foreign_key(self, separate_class_name_and_id_with_underscore) end |
#humanize ⇒ Object
Capitalizes the first word and turns underscores into spaces and strips _id, so “employee_salary” becomes “Employee salary” and “author_id” becomes “Author”.
43 44 45 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 43 def humanize Inflector.humanize(self) end |
#pluralize ⇒ Object
7 8 9 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 7 def pluralize Inflector.pluralize(self) end |
#singularize ⇒ Object
11 12 13 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 11 def singularize Inflector.singularize(self) end |
#tableize ⇒ Object
33 34 35 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 33 def tableize Inflector.tableize(self) end |
#titleize ⇒ Object Also known as: titlecase
20 21 22 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 20 def titleize Inflector.titleize(self) end |
#underscore ⇒ Object
25 26 27 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 25 def underscore Inflector.underscore(self) end |