From: Rich Kilmer Date: 2001-12-04T06:46:20+09:00 Subject: [ruby-talk:27378] RE: Selecting class based on external information > -----Original Message----- > From: Jeff Putsch [mailto:putsch@hf.mxim.com] > Sent: Monday, December 03, 2001 4:25 PM > To: ruby-talk ML > Subject: [ruby-talk:27371] Selecting class based on external information > > > Howdy, > > I'm trying to select the class for an instance variable based on external > information and cannot figure out how. For example: > > class Host > # variables and routines common to all hosts, default values for > # OS specific things > end > > class SunOS < Host > # overrides for OS specific things > end > > # main routine would do this... > > OSname = `/bin/uname -s`.chomp > > myHost = OSname.new # on a Solaris system this should > # be equivalent to doing "myHost = SunOS.new" try: myHost = eval(OSname+".new") > > The initialization of "myHost" is where I run into trouble. I can > not figure > out how to do this. I'm sure Ruby has some "magic" to get this done, but > it's beyond me ... > > Jeff. > -- > Jeff Putsch Email: putsch@mxim.com > Maxim Integrated Products Office: (503)547-2037 > High Frequency CAD Engineering