diff options
author | Xavier Noria <fxn@hashref.com> | 2010-03-02 22:29:58 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-03-02 22:29:58 +0100 |
commit | 3084898ca6d98d37da64705d755e189e36040339 (patch) | |
tree | f13d66adb4b529b18f4995b2a8c75bb85caa6851 /railties/guides/source | |
parent | 88c01b3f10d8bc47359f2f69f69a606ace5fc0f6 (diff) | |
download | rails-3084898ca6d98d37da64705d755e189e36040339.tar.gz rails-3084898ca6d98d37da64705d755e189e36040339.tar.bz2 rails-3084898ca6d98d37da64705d755e189e36040339.zip |
AS guide: documents String#classify
Diffstat (limited to 'railties/guides/source')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 22 |
1 files changed, 21 insertions, 1 deletions
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+. <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 |