From: Daniel Nugent Date: 2006-02-21T15:42:46+09:00 Subject: Re: dirty ranges Hrmmm.. the second example that Dirk gives is pretty ugly. I shouldthink that you could simply call clone on the begining value of therange and get a more desirable result. I don't know if a deep-copywould be required, and if it were, it's only aMarshal.load(Marshal.dump(obj)) away, right? On 2/20/06, David Vallner wrote:> D�a Utorok 21 Febru�r 2006 04:38 George Ogata nap�sal:> > 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.> >>> Pffft. Doesn't even flinch.>> ruby < rng1 = ("a".."g")> rng1.each { |char|> if char == "d"> rng1.end[0] = "j"> end> puts char> }> rng2 = ("a".."j")> rng2.each { |char|> if char == "g"> rng2.end[0] = "d"> end> puts char> }> END>> Outputs:>> a> b> c> d> e> f> g> a> b> c> d> e> f> g> h> i> j>>> Of course, I have absolutely NO idea at all why, and don't particularly feel> like reading Ruby core source.>> David Vallner>> ---Dan Nugent