Fix String#slice! raise TypeError or return invalid value.

This commit is contained in:
TOMITA Masahiro
2014-11-23 21:26:50 +09:00
parent 2c04f4029f
commit 0a0afa7c6a
+4 -3
View File
@@ -181,6 +181,7 @@ class String
ed = arg1.end
beg += self.size if beg < 0
ed += self.size if ed < 0
ed -= 1 if arg1.exclude_end?
validated = true
elsif arg1.kind_of?(String)
validated = true
@@ -198,18 +199,18 @@ class String
unless str == nil || str == ""
if arg1 != nil && arg2 !=nil
idx = arg1 >= 0 ? arg1 : self.size+arg1
str2 = self[0...idx] + self[idx+arg2..-1]
str2 = self[0...idx] + self[idx+arg2..-1].to_s
else
if arg1.kind_of?(Range)
idx = beg >= 0 ? beg : self.size+beg
idx2 = ed>= 0 ? ed : self.size+ed
str2 = self[0...idx] + self[idx2+1..-1]
str2 = self[0...idx] + self[idx2+1..-1].to_s
elsif arg1.kind_of?(String)
idx = self.index(arg1)
str2 = self[0...idx] + self[idx+arg1.size..-1] unless idx == nil
else
idx = arg1 >= 0 ? arg1 : self.size+arg1
str2 = self[0...idx] + self[idx+1..-1]
str2 = self[0...idx] + self[idx+1..-1].to_s
end
end
self.replace(str2) unless str2 == nil