Hi,
Is it possible in Ruby to define a new non-singleton class based on a singleton class?
I tried something like this (snip):
module SomeModule
extend self
class Singleton;end
end
class NonSingleton
include SomeModule
end
nonsingleton = NonSingleton.new
But of course to you gurus it's already evident that this won't work as I expected.
Basically what I want is to re-use the functionality of the Singleton class, without affecting it's behavior in any way. Is it possible?
After further investigation, it would seem that this ain't possible at all (please correct me if I'm wrong). Would a hack like following be too fugly/messy?
singleton = File.read('some_singleton.rb')
non_singleton = eval(singleton.gsub('include Singleton', ''))
# Or perhaps:
non_singleton = eval(singleton.gsub('module SomeModule', 'module MyOwnModule'))