From: Joel VanderWerf Date: 2006-06-12T06:00:34+09:00 Subject: Re: Dynamic class change? Mark Noworolski wrote: > As time passes, when I hear a new MAC start talking, I dynamically > create a corresponding object. So, if the first thing I hear is > something a Nic says, a Nic object can spring into existence, ditto > for Nic2, etc. So far, seems reasonable. > > However, the similar things will sometimes appear as a Nic, then say > something new and exciting that indicates that they are actually Nic2 > objects (or Nic3, for example). It sounds like you could get away with something like htis: class Nic attr_accessor :mac end module Nic2 def do_nic2_stuff puts "nic2 at #{mac}!" end end module Nic3 end # when you first hear it nic = Nic.new nic.mac = "12:23..." # later when you have more info nic.extend Nic2 nic.do_nic2_stuff # ==> nic2 at 12:23...! This will work as long as the information you get about these objects is _monotone_: you never have to back out of extending a nic instance with modules. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407