From: Phrogz Date: 2007-02-17T03:55:04+09:00 Subject: Re: Oppinions on RCR for dup on immutable classes On Feb 16, 11:43 am, "Robert Dober" wrote: > On 2/16/07, Gregory Brown wrote: > > >> a = 3 > > => 3 > > >> b = a.dup rescue a > > => 3 > > >> b > > => 3 > > > What's so bad about that? > > I would ask the question: Why do you dup a? > The answer is, I presume, because I will modify the duplicate and I > do not want to modify the original. > ok so let us follow our code > > b= a.dup rescue a > .. > > b.mutating_method > what will happen now? I'm not sure what your point is, Robert. Is it: a) See, there's no point in duplicating an immutable object, since the only reason to #dup is so you can mutate the instance later, and anything you tried to do to mutate it would fail later on. or is it b) You should never ever write "a.dup rescue a" because it will give you strange problems if a might refer to a mutable object that doesn't respond to #dup. ?