Array#collect is faster than Array#inject
Also add some more tests.
This commit is contained in:
parent
282515d907
commit
1613973929
2 changed files with 14 additions and 3 deletions
|
@ -392,7 +392,8 @@ class WikiController < ApplicationController
|
|||
def truncate(text, length = 30, truncate_string = '...')
|
||||
return text if text.length <= length
|
||||
len = length - truncate_string.length
|
||||
text.split.inject('') do |t, word|
|
||||
t = ''
|
||||
text.split.collect do | word|
|
||||
if t.length + word.length <= len
|
||||
t << word + ' '
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue