From: jmichel@...2.institut.math.jussieu.fr (Jean Michel) Date: 2001-08-16T07:32:54+09:00 Subject: [ruby-talk:19850] Re: Why not?: Assigning to self >On Tuesday 14 August 2001 09:38 am, Dave Thomas wrote: > >> Perhaps if we could see an actual example of where this is needed we >> could discuss this better. I know there was some talk a while back of >> some code that handled (I think) archives or somesuch. Could be see >> the code for this so we could think about it. > I came upon something which is perhaps an exemple where one might want to change self, or perhaps just I did not find the right way to achieve my aim. I came upon a situation which could be handled nicely by adding a couple of methods to the class Range (I will elaborate the situation in a further message if people are interested): Class Range def shrink_up @begin+=1 end def shrink_down @end-=1 end end Well, this does not work since begin and end are not writable attributes (nor attributes at all, in fact). The next try would be :) Class Range def shrink_up self=(begin+1..end) end def shrink_down self=(begin..end-1) end end Here I am stuck: how to add such methods to range or to a class derived from range? It seems that by design ranges, contrary to some other classes like strings or arrays, are immutable. Is this a conscious design decision which has advantages, or did it happen by chance? Best regards, Jean Michel