184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/ruuuby/extensions.rb', line 184
def ensure_ending!(ending)
Ruuuby::Params::check_string(ending)
return self if ending == '' || self.end_with?(ending)
len_this = self.length
return self << ending if len_this == 0
last_matched = ''
len_ending = ending.length
delta = 0
while delta <= len_this && delta <= len_ending
ending_of_this = self[(len_this-1-delta)..(len_this-1)]
starting_of_end = ending[0..delta]
last_matched = starting_of_end if ending_of_this == starting_of_end
delta += 1
end
self << (last_matched == '' ? ending : ending[last_matched.length..len_ending-1])
end
|