I am trying to do something like the following code sample:
class Base
class << self
attr :my_name, true
end
def show_name
self.class.my_name
end
end
class Maker
def Maker.create_class(class_name)
Class.new(Base) { self.my_name = class_name }
end
end
HEH = Maker.create_class("HEH")
heh_instance = HEH.new
p heh_instance.kind_of?(Base)
p heh_instance.show_name
class ExtendedHEH < HEH
end
p ExtendedHEH.new.show_name
I want the last 'p' to print out "HEH". I understand why Base.show_name
is not working for the extended class (self resolves to itself, which will grab the extended class 'ExtendedHEH')... but I do not understand how I can access
the singleton class to get at "HEH". Any thoughts?
-Tom
···
--
+ http://www.tc.umn.edu/~enebo +---- mailto:enebo@acm.org ----+
Thomas E Enebo, Protagonist | "Luck favors the prepared |
> mind." -Louis Pasteur |