Levin Alexander
7/7/2005 4:38:00 PM
Hi,
How can I build a Class that works like the built-in "Struct" and returns
new anonymous classes based on arguments to MyClass.new?
A simplified example:
with_foo = MyClass.new(:foo)
one = with_foo.new
one.foo
with_bar = MyClass.new(:bar)
two = with_bar.new
two.bar
I tried to do:
class MyClass
def self.new_class(method_name)
c = Class.new(self)
c.class_eval do
define_method(method_name) { puts "method #{method_name} called" }
end
return c
end
end
How can I rename 'new_class' to 'new' without breaking 'new' in derieved
classes?
Thank You,
Levin