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:
parent
ddee6f24a5
commit
dabcfc4914
1 changed files with 3 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue