From: Ian Trudel Date: 2009-03-01T05:50:59+09:00 Subject: Re: Marshal.load does not create new instances? > Ian, I'm not sure I understand what you want. AFAIK Marshal only works > if you have the same class definitions on both sides. Why is this a > problem for you? This is actually how I use Marshal. It works fine if I have only one version in one given Ruby program. The problem resides in loading different files which may contain one version or another of the given class definition. There are sometimes additional (or less) instance variables and methods, different implementation of certain methods, etc. depending on the version of the class. Mmm. collision problems, Capitain! My initial hope was on defining the main class in such way to delegate to other classes (named and implemented according to its version). In my twisted mind, I had imagined something that I could set the delegator to a certain class before loading the data, just like any other proxy, and then use it; or at least before using methods or accessors. > Ian, you should be aware of one thing: class definitions are not > serialized - no programming language that I know does this. And there > are probably good reasons (security, efficiency probably). Understandably. :) > 1. use OpenStruct > 2. use Hash > 3. change your class Data to store attributes in a single Hash only Once again a good idea! Unfortunately, it is not just about data but also about class and instance methods and their specific implementation. Would it mean that I could mixin the instance of OStruct with my specific version of a class (as a module) at that point? > You can use tricks as 7stud suggested although I feel wary about this. > I would probably choose a different solution based on the > requirements (which are not fully clear to me). If you just need > changing sets of attributes then these options might work: I have data files generated by different softwares. These files are generated according to a given class but the implementation (accessors, methods, etc.) are slightly different according to the software. They share the same name, basic functionalities and data though they have differences according to their version. I would like to be able to load and use them within my Ruby program, any or many of these generated files at the same time without collision. Requirement was that I do not have access to the original source of the softwares and I do have to reimplement and test each version all by myself. We should perhaps see the problem as if it was extreme: let's imagine that we have multiple programs which have each a class Data but is completely different (no similar instance variables nor methods, nothing in common at all). No access to those programs and yet have to load all the files within a single Ruby program. What one would do? Thanks for your help, guys! Regards, Ian -- Posted via http://www.ruby-forum.com/.