From: Mike Stok Date: 2001-10-26T08:31:19+09:00 Subject: [ruby-talk:23378] Re: Unexpected results using File::SEPARATOR On Fri, 26 Oct 2001, Paul Brannan wrote: > I did something like this: > > foo = File::SEPARATOR > foo << "foo" > > bar = File::SEPARATOR > bar << "bar" > > p foo, bar > > And I got this: > > "/foobar" > "/foobar" > > This is not what I expected, but it makes sense, because I am modifing > File::SEPARATOR. Would it make sense to freeze File::SEPARATOR to keep > this from happening? With what other "constants" might this problem > occur? foo and bar refer to the same thing, maybe you want to make a copy of the referent of File::SEPARATOR e.g. [mike@ratdog mike]$ irb irb(main):001:0> foo = File::SEPARATOR "/" irb(main):002:0> bar = File::SEPARATOR "/" irb(main):003:0> foo.equal?(bar) true irb(main):004:0> foo.id == bar.id true irb(main):005:0> foo == bar true irb(main):006:0> foo = File::SEPARATOR.dup "/" irb(main):007:0> bar = File::SEPARATOR.dup "/" irb(main):008:0> foo.equal?(bar) # are the objects the same? false irb(main):009:0> foo == bar # are the values in the objects the same? true irb(main):010:0> foo << 'foo' "/foo" irb(main):011:0> bar << 'bar' "/bar" You might want to look at the descriptions of dup and clone availabe at http://www.rubycentral.com/book/ref_c_object.html and also the section on Variables near the end of http://www.rubycentral.com/book/tut_classes.html (in the book the diagram helps a little) Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA | Fingerprint 0570 71CD 6790 7C28 3D60 | 75D2 9EC4 C1C0 0599 13DA