From: dblack@... Date: 2007-02-15T12:19:13+09:00 Subject: Re: Creating a second instance of a singleton class? Hi -- On Thu, 15 Feb 2007, ara.t.howard@noaa.gov wrote: > On Thu, 15 Feb 2007, Steve Midgley wrote: > >> Another way to describe what I want to do: >> >> 1) create a class "Test" >> 2) create an instance of Test: "test1" >> 3) modify test1's class definition, creating a singleton class >> 4) Somehow "promote" or copy this singleton class to be a full fledged >> class as "Test2" >> 5) Create an instance of "Test2" as "test2" > > harp:~ > cat a.rb > require 'rubygems' > require 'prototype' Are you sure you need those for your example? >> I can't see why Ruby would object inherently to copying all the class >> methods of a singleton into a new class object (which is all I want - just >> a template of the singleton class's methods - no class variables or >> whatnot). > > you have to have the the class variables if you have class methods. > otherwise this > > class C > @x = 42 > def self.x() @x end > end > > won't work That's not a class variable, though -- but I'm a bit confused by Steve's reference to class methods. Steve, why are you referring to class methods? :-) David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)