aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2014-05-06 21:25:52 +0200
committerXavier Noria <fxn@hashref.com>2014-05-06 21:35:40 +0200
commitdaaa21bc7d20f2e4ff451637423a25ff2d5e75c7 (patch)
tree10bbaa94ccaad20e1507dc29ed0c9153e18c18a9 /guides/source
parentd97581921b0ff7a31ce63fef4687437594f38447 (diff)
downloadrails-daaa21bc7d20f2e4ff451637423a25ff2d5e75c7.tar.gz
rails-daaa21bc7d20f2e4ff451637423a25ff2d5e75c7.tar.bz2
rails-daaa21bc7d20f2e4ff451637423a25ff2d5e75c7.zip
several enhancements to humanize [closes #12288]
* Strips leading underscores. * Changes some unnecessary gsub!s to sub!s. * Replaces some anchors ^, $ with \A, \z. * Documents that human inflection rules are applied. * Documents that words are downcased except acronyms. * Adds an example with an acronym. * Rewords docs.
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/active_support_core_extensions.md29
1 files changed, 22 insertions, 7 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 5a4e15cfa9..1ac7ecc78f 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -1768,21 +1768,36 @@ NOTE: Defined in `active_support/core_ext/string/inflections.rb`.
#### `humanize`
-The method `humanize` gives you a sensible name for display out of an attribute name. To do so it replaces underscores with spaces, removes any "_id" suffix, and capitalizes the first word:
+The method `humanize` tqweaks an attribute name for display to end users.
+
+Specifically performs these transformations:
+
+ * Applies human inflection rules to the argument.
+ * Deletes leading underscores, if any.
+ * Removes a "_id" suffix if present.
+ * Replaces underscores with spaces, if any.
+ * Downcases all words except acronyms.
+ * Capitalizes the first word.
+
+The capitalization of the first word can be turned off by setting the
++:capitalize+ option to false (default is true).
```ruby
-"name".humanize # => "Name"
-"author_id".humanize # => "Author"
-"comments_count".humanize # => "Comments count"
+"name".humanize # => "Name"
+"author_id".humanize # => "Author"
+"author_id".humanize(capitalize: false) # => "author"
+"comments_count".humanize # => "Comments count"
+"_id".humanize # => "Id"
```
-The capitalization of the first word can be turned off by setting the optional parameter `capitalize` to false:
+If "SSL" was defined to be an acronym:
```ruby
-"author_id".humanize(capitalize: false) # => "author"
+'ssl_error'.humanize # => "SSL error"
```
-The helper method `full_messages` uses `humanize` as a fallback to include attribute names:
+The helper method `full_messages` uses `humanize` as a fallback to include
+attribute names:
```ruby
def full_messages