Skip to content
Permalink
Browse files

Merge pull request #595 from kachick/fix-string-check_frozen

Fix side effect methods in String when self is a frozen object
  • Loading branch information
alex committed Apr 10, 2013
2 parents e6b484d + 656b4f1 commit 771db4f744514d4e9717fb70cf7b5116e87b7bea

This file was deleted.

@@ -12,8 +12,6 @@ fails:String#chomp when passed '' does not remove a final carriage return
fails:String#chomp when passed '\n' removes one trailing newline
fails:String#chomp when passed '\n' removes one trailing carriage return
fails:String#chomp when passed '\n' removes one trailing carrige return, newline pair
fails:String#chomp! raises a RuntimeError on a frozen instance when it is modified
fails:String#chomp! raises a RuntimeError on a frozen instance when it would not be modified
fails:String#chomp! when passed no argument removes one trailing newline
fails:String#chomp! when passed no argument removes one trailing carriage return
fails:String#chomp! when passed no argument removes one trailing carrige return, newline pair
@@ -1,4 +1,2 @@
fails:String#chop returns a new string with the last character removed
fails:String#chop! behaves just like chop, but in-place
fails:String#chop! raises a RuntimeError on a frozen instance that is modified
fails:String#chop! raises a RuntimeError on a frozen instance that would not be modified

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -446,6 +446,7 @@ def method_times(self, space, times):
return self.strategy.mul(space, self.str_storage, times)

@classdef.method("<<")
@check_frozen()
def method_lshift(self, space, w_other):
assert isinstance(w_other, W_StringObject)
self.extend(space, w_other)
@@ -496,6 +497,7 @@ def method_to_sym(self, space):
return space.newsymbol(space.str_w(self))

@classdef.method("clear")
@check_frozen()
def method_clear(self, space):
self.clear(space)
return self
@@ -645,24 +647,28 @@ def method_split(self, space, w_sep=None, limit=0):
)

@classdef.method("swapcase!")
@check_frozen()
def method_swapcase_i(self, space):
self.strategy.to_mutable(space, self)
changed = self.strategy.swapcase(self.str_storage)
return self if changed else space.w_nil

@classdef.method("upcase!")
@check_frozen()
def method_upcase_i(self, space):
self.strategy.to_mutable(space, self)
changed = self.strategy.upcase(self.str_storage)
return self if changed else space.w_nil

@classdef.method("downcase!")
@check_frozen()
def method_downcase_i(self, space):
self.strategy.to_mutable(space, self)
changed = self.strategy.downcase(self.str_storage)
return self if changed else space.w_nil

@classdef.method("capitalize!")
@check_frozen()
def method_capitalize_i(self, space):
self.strategy.to_mutable(space, self)
changed = self.strategy.capitalize(self.str_storage)
@@ -783,6 +789,7 @@ def method_tr(self, space, source, replacement):
return space.newstr_fromchars(new_string) if new_string else string

@classdef.method("tr!", source="str", replacement="str")
@check_frozen()
def method_tr_i(self, space, source, replacement):
new_string = self.tr_trans(space, source, replacement, False)
self.replace(space, new_string)
@@ -795,6 +802,7 @@ def method_tr_s(self, space, source, replacement):
return space.newstr_fromchars(new_string) if new_string else string

@classdef.method("tr_s!", source="str", replacement="str")
@check_frozen()
def method_tr_s_i(self, space, source, replacement):
new_string = self.tr_trans(space, source, replacement, True)
self.replace(space, new_string)
@@ -961,6 +969,7 @@ def gsub_replacement_to_s(self, space, w_replacement):
return space.any_to_s(w_replacement)

@classdef.method("chomp!")
@check_frozen()
def method_chomp_i(self, space, w_newline=None):
if w_newline is None:
w_newline = space.globals.get(space, "$/")
@@ -974,19 +983,22 @@ def method_chomp_i(self, space, w_newline=None):
return self if changed else space.w_nil

@classdef.method("chop!")
@check_frozen()
def method_chop_i(self, space):
self.strategy.to_mutable(space, self)
changed = self.strategy.chop(self.str_storage)
return self if changed else space.w_nil

@classdef.method("reverse!")
@check_frozen()
def method_reverse_i(self, space):
self.strategy.to_mutable(space, self)
self.strategy.reverse(self.str_storage)
return self

@classdef.method("next!")
@classdef.method("succ!")
@check_frozen()
def method_succ_i(self, space):
self.strategy.to_mutable(space, self)
self.strategy.succ(self.str_storage)

0 comments on commit 771db4f

Please sign in to comment.
You can’t perform that action at this time.