lib/cliutils/ext/string_extensions.rb in cliutils-2.2.5 vs lib/cliutils/ext/string_extensions.rb in cliutils-2.2.6
- old
+ new
@@ -58,9 +58,10 @@
# Truncates a string to a certain length
# and adds an ellipsis after.
# @param [Fixnum] length The length to truncate at
# @return [String]
def truncate(length = 30)
+ return self if self.length < length
self[0..length].gsub(/\s\w+\s*$/, '...')
end
# Makes the associated string white.
# @return [void]