Skip to content

Commit dabcfc4

Browse files
committed
Better not mutate the given options Hash
1 parent ddee6f2 commit dabcfc4

File tree

1 file changed

+3
-3
lines changed
  • activesupport/lib/active_support/core_ext/string

1 file changed

+3
-3
lines changed

activesupport/lib/active_support/core_ext/string/filters.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def squish!
4141
def truncate(truncate_at, options = {})
4242
return dup unless length > truncate_at
4343

44-
options[:omission] ||= '...'
45-
length_with_room_for_omission = truncate_at - options[:omission].length
44+
omission = options[:omission] || '...'
45+
length_with_room_for_omission = truncate_at - omission.length
4646
stop = \
4747
if options[:separator]
4848
rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
4949
else
5050
length_with_room_for_omission
5151
end
5252

53-
"#{self[0, stop]}#{options[:omission]}"
53+
"#{self[0, stop]}#{omission}"
5454
end
5555
end

0 commit comments

Comments
 (0)