Skip to content

Commit

Permalink
AS guide: documents String#classify
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Mar 2, 2010
1 parent 88c01b3 commit 3084898
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion railties/guides/source/active_support_core_extensions.textile
Expand Up @@ -1457,13 +1457,33 @@ The method +tableize+ is +underscore+ followed by +pluralize+.
<ruby>
"Person".tableize # => "people"
"Invoice".tableize # => "invoices"
"InvoiceLine".tableize # => "invoice_lines"
"InvoiceLine".tableize # => "invoice_lines"
</ruby>

As a rule of thumb, +tableize+ returns the table name that corresponds to a given model for simple cases. The actual implementation in Active Record is not straight +tableize+ indeed, because it also demodulizes de class name and checks a few options that may affect the returned string.

NOTE: Defined in +active_support/core_ext/string/inflections.rb+.

h5. +classify+

The method +classify+ is the inverse of +tableize+. It gives you the class name corresponding to a table name:

<ruby>
"people".classify # => "Person"
"invoices".classify # => "Invoice"
"invoice_lines".classify # => "InvoiceLine"
</ruby>

The method understands qualified table names:

<ruby>
"highrise_production.companies".classify # => "Company"
</ruby>

Note that +classify+ returns a class name as a string. You can get the actual class object invoking +constantize+ on it, explained next.

NOTE: Defined in +active_support/core_ext/string/inflections.rb+.

h3. Extensions to +Numeric+

h4. Bytes
Expand Down

0 comments on commit 3084898

Please sign in to comment.