------ art_4811_819280.1143477685872 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 3/27/06, parisnight / gmail.com <parisnight / gmail.com> wrote: > > It would be nicer to be able to > instantiate a generic superclass object, read its data, then based on > the values of the tags specialize the object to become a square or > triangular object and then the specialized object can read its data to > become more specific, and so on. Each child class could parse the bits > it knows about, and the object becomes more specialized as it reads > more. > In CLOS there are ways around this such as described in Peter Seibel's > book. > > Does anyone know of any Ruby techniques that work well when reading > data containing tagged unions? > > Thanks! Bob Hmm maybe I did not understand your request completely but the following seems a reasonable approach to me Allow an object of the superclass to be passed into the constructor of the subclass. -------------------------------------9<----------------------------- class Shape attr :nodes, :info def initialize( info, nodes = nil ) @nodes = nodes ... def size ... end end class Rectangle attr_accessor :width, :height def initialize( aShape, width, height ) nodes = comp( width, height) super "rectangle", nodes @width = width ... end end now you start reading myShape = Shape.new( :bla ) discovery is done myShape = Rectangle.new( myShape, 42, 27 ) ------------------------------->6------------------------------ but maybe my understanding of the problem is too superficial. Robert -- Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------ art_4811_819280.1143477685872--