On Sat, 29 Nov 2003 04:47:37 +0900, Hal Fulton wrote: > Simon Strandgaard wrote: >> a = Iterator.new(42) >> a += 1 # Question: How to do selfassignment ? >> a.close >> # 42 never gets closed! > > What's happening here is that += is dependent on +, yet it is still > an assignment. > > a += 1 is equivalent to a=a+1; so as you can see, a new object is > created and assigned to a. I know that. What I don't know, are if there are any tricks when dealing with '+=' ? > You could always implement methods like succ or add that would > change the value without changing the object's identity. Yes I already have #next and #prev. > Does this clarify any? Conclusion: providing a PLUS ('+') operator, can be dangerous because the user can invoke '+=' and the instance will not get #closed correctly. safer to undef '+'. -- Simon Strandgaard