aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-02 01:34:39 +0200
committerMikel Lindsaar <raasdnil@gmail.com>2010-06-03 23:32:11 +1000
commitf1fa3a35585913b936b43164d77826380fec20bf (patch)
tree01e5f01b3834ce56137a098675f34c5a09b2d38a /activesupport
parent83a58e066090c5238822b712e0cfa8b72ddb02e5 (diff)
downloadrails-f1fa3a35585913b936b43164d77826380fec20bf.tar.gz
rails-f1fa3a35585913b936b43164d77826380fec20bf.tar.bz2
rails-f1fa3a35585913b936b43164d77826380fec20bf.zip
revises the documentation of String#truncate and the truncate helper
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/string/filters.rb22
1 files changed, 9 insertions, 13 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb
index cdd86a836f..e15a1df9c9 100644
--- a/activesupport/lib/active_support/core_ext/string/filters.rb
+++ b/activesupport/lib/active_support/core_ext/string/filters.rb
@@ -20,25 +20,21 @@ class String
self
end
- # Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>.
- # The last characters will be replaced with the <tt>:omission</tt> (defaults to "...")
- # for a total length not exceeding <tt>:length</tt>.
+ # Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>:
#
- # Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
+ # "Once upon a time in a world far far away".truncate(27)
+ # # => "Once upon a time in a wo..."
#
- # ==== Examples
+ # The last characters will be replaced with the <tt>:omission</tt> string (defaults to "...")
+ # for a total length not exceeding <tt>:length</tt>:
#
- # "Once upon a time in a world far far away".truncate(30)
- # # => Once upon a time in a worl...
+ # "Once upon a time in a world far far away".truncate(27, :separator => ' ')
+ # # => "Once upon a time in a..."
#
- # "Once upon a time in a world far far away".truncate(30, :separator => ' ')
- # # => Once upon a time in a world...
- #
- # "Once upon a time in a world far far away".truncate(14)
- # # => Once upon a...
+ # Pass a <tt>:separator</tt> to truncate +text+ at a natural break:
#
# "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)")
- # # => And they f... (continued)
+ # # => "And they f... (continued)"
def truncate(length, options = {})
text = self.dup
options[:omission] ||= "..."