From: George Ogata Date: 2006-02-21T12:38:32+09:00 Subject: Re: dirty ranges dvandeun@vub.spam-me-not.ac.be (Dirk van Deun) writes: > It seems that you can do destructive operations on the minimum element > of a range, but not on the maximum element (well, you can, but it > does not have any effect): > > irb(main):001:0> rng="a".."z" > => "a".."z" > irb(main):002:0> rng.min[0]="b" > => "b" > irb(main):003:0> rng.max[0]="y" > => "y" > irb(main):004:0> rng > => "b".."z" You can modify the endpoints if you reference them using #begin and #end: irb(main):001:0> r = 'a'..'z' => "a".."z" irb(main):002:0> r.begin << '!' => "a!" irb(main):003:0> r.end << '!' => "z!" irb(main):004:0> r => "a!".."z!" #begin and #end are direct accessors to the endpoint objects, whereas #max is calculated, taking into account end-closedness. It should not be surprising, then, that #max and #end return different objects. But I suggest not modifying range endpoints at all; Ranges themselves are immutable, so changing their value indirectly like that is kinda going against the grain. And of course, if you ever modify your #end while iterating over the range, it's nasal demons.