1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Better not mutate the given options Hash

This commit is contained in:
Akira Matsuda 2013-07-10 23:09:33 +09:00
parent ddee6f24a5
commit dabcfc4914

View file

@ -41,8 +41,8 @@ class String
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 @@ class String
length_with_room_for_omission
end
"#{self[0, stop]}#{options[:omission]}"
"#{self[0, stop]}#{omission}"
end
end