The Inflector transforms words from singular to plural, class names to
table names, modularized class names to ones without, and class names to
foreign keys. The default inflections for pluralization, singularization,
and uncountable words are kept in inflections.rb.
| Classes |
| Inflections |
A singleton instance of this class is yielded by Inflector.inflections,
which can then be used to specify additional inflection rules. Examples:
|
| Public Methods |
| camelize |
By default, camelize converts strings to UpperCamelCase. If the argument to
camelize is set to ":lower" then camelize produces
lowerCamelCase.
|
| classify |
Create a class name from a table name like Rails does for table names to
models. Note that this returns a string and not a Class. (To convert to an
actual class follow classify with constantize.)
|
| constantize |
Constantize tries to find a declared constant with the name specified in
the string. It raises a NameError when the name is not in CamelCase or is
not initialized.
|
| dasherize |
Replaces underscores with dashes in the string.
|
| demodulize |
Removes the module part from the expression in the string
|
| foreign_key |
Creates a foreign key name from a class name.
separate_class_name_and_id_with_underscore sets whether the method
should put ‘_’ between the name and ‘id’.
|
| humanize |
Capitalizes the first word and turns underscores into spaces and strips
_id. Like titleize, this is meant for creating pretty output.
|
| inflections |
|
| ordinalize |
Ordinalize turns a number into an ordinal string used to denote the
position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
| pluralize |
Returns the plural form of the word in the string.
|
| singularize |
The reverse of pluralize, returns the singular form of a word in a string.
|
| tableize |
Create the name of a table like Rails does for models to table names. This
method uses the pluralize method on the last word in the string.
|
| titleize |
Capitalizes all the words and replaces some characters in the string to
create a nicer looking title. Titleize is meant for creating pretty output.
It is not used in the Rails internals.
|
| underscore |
The reverse of camelize. Makes an underscored form from the
expression in the string.
|
<code/>and<pre/>for code samples.