From: James Gray Date: 2009-06-02T07:14:11+09:00 Subject: [ruby-core:23663] Re: [Bug #1550] String#lstrip! raises RuntimeError on Frozen String Despite Making No Changes On Jun 1, 2009, at 5:07 PM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:23657] [Bug #1550] String#lstrip! raises > RuntimeError on Frozen String Despite Making No Changes" > on Mon, 1 Jun 2009 20:13:49 +0900, Run Paint Run Run > writes: > > |Calling String#lstrip! on a frozen string raises a RuntimeError > even if the string was not changed. String#rstrip! doesn't raise an > exception in this scenario. I believe that the latter behaviour is > correct; #lstrip! should only raise a RuntimeError if the string > would be changed. > > I admit the inconsistency. There could be two policies: > > (a) methods should raise RuntimeError only when actual changes are > made, because it should detect changes. > > (b) methods should eagerly raise RuntimeError when they could > possibly make changes, to detect modify attempt to frozen > strings (that most likely caused by bugs) earlier. > > Currently both policies mixed. You've suggested the former, I'd > rather prefer the latter. Any opinion? I really feel (b) is the better choice. The fact that it worked is pretty irrelevant. It shouldn't have worked. Either you didn't need to call something like strip!() and you can remove it, or you sometimes do need to call it and you'll need to change the code not to work on frozen data. Either way, you need to change your code and the error shows that. James Edward Gray II