From: Phrogz Date: 2007-02-17T15:45:11+09:00 Subject: Re: Oppinions on RCR for dup on immutable classes On Feb 16, 4:47 pm, "Gregory Brown" wrote: > On 2/16/07, Phrogz wrote: > > I personally believe that returning self for symbols, fixnums, true, > > false, and nil is not bad or dangerous in any way. Can you provide a > > single example (even if contrived) where this could produce an > > unintended result? I can only come up with one myself, and it's too > > contrived for me to consider it a danger. > > the only things I can think of involve singleton methods > > >> def nil.foo > >> "hi there" > >> end > => nil > >> nil.foo > => "hi there" > >> b = nil.dup > > TypeError: can't dup NilClass > from (irb):13:in `dup' > from (irb):13 > > >> def b.bar; "confusing?"; end > > Imagine no error was thrown by that dup. > > bar would be defined both on the duped (really not duped at all) nil > in your b variable, and on nil itself. > > This of course is contrived, but it would be surprising behaviour. (I think) A very good case. Enough so that I change my vote from "change dup" to "leave things as they are".