From 3084898ca6d98d37da64705d755e189e36040339 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 2 Mar 2010 22:29:58 +0100 Subject: AS guide: documents String#classify --- .../source/active_support_core_extensions.textile | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 2571c83dd8..26e4113edf 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1457,13 +1457,33 @@ The method +tableize+ is +underscore+ followed by +pluralize+. "Person".tableize # => "people" "Invoice".tableize # => "invoices" -"InvoiceLine".tableize # => "invoice_lines" +"InvoiceLine".tableize # => "invoice_lines" 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: + + +"people".classify # => "Person" +"invoices".classify # => "Invoice" +"invoice_lines".classify # => "InvoiceLine" + + +The method understands qualified table names: + + +"highrise_production.companies".classify # => "Company" + + +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 -- cgit v1.2.3