提交 dabcfc49 编写于 作者: A Akira Matsuda

Better not mutate the given options Hash

上级 ddee6f24
......@@ -41,8 +41,8 @@ def squish!
def truncate(truncate_at, options = {})
return dup unless length > truncate_at
options[:omission] ||= '...'
length_with_room_for_omission = truncate_at - options[:omission].length
omission = options[:omission] || '...'
length_with_room_for_omission = truncate_at - omission.length
stop = \
if options[:separator]
rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
......@@ -50,6 +50,6 @@ def truncate(truncate_at, options = {})
length_with_room_for_omission
end
"#{self[0, stop]}#{options[:omission]}"
"#{self[0, stop]}#{omission}"
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册