From: Eric Hodel Date: 2006-02-08T06:40:23+09:00 Subject: Re: marshalling constants On Feb 7, 2006, at 11:38 AM, Brian Buckley wrote: > Hello, > > When one marshals a constant and later unmarshals it, a brand new > object > appears to be created during unmarshalling. This seems wasteful, > especially > in cases when constants are large (contain many attributes). Is it > possible > to customize marshal for a class (or for singleton objects of the > class) so > that unmarshalling a constant simply returns the already existing > constant > rather than creating a new one? I've noticed Fixnum's exhibit this > behavior. How do you know that a Marshal string is identical to a constant without loading it? Note that Ruby doesn't really have constants. Instead it has frozen objects which aren't quite the same thing. $ ruby A = 1 A = 1 -:2: warning: already initialized constant A $ ruby s = '' s.freeze s.replace 'x' -:3:in `replace': can't modify frozen string (TypeError) from -:3 -- Eric Hodel - drbrain@segment7.net - http://segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com