L
Levin Alexander
Hi,
How can I build a Class that works like the built-in "Struct" and returns=
=20
new anonymous classes based on arguments to MyClass.new?
A simplified example:
with_foo =3D MyClass.newfoo)
one =3D with_foo.new
one.foo
with_bar =3D MyClass.newbar)
two =3D with_bar.new
two.bar
I tried to do:
class MyClass
def self.new_class(method_name)
c =3D 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 =
=20
classes?
Thank You,
Levin
How can I build a Class that works like the built-in "Struct" and returns=
=20
new anonymous classes based on arguments to MyClass.new?
A simplified example:
with_foo =3D MyClass.newfoo)
one =3D with_foo.new
one.foo
with_bar =3D MyClass.newbar)
two =3D with_bar.new
two.bar
I tried to do:
class MyClass
def self.new_class(method_name)
c =3D 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 =
=20
classes?
Thank You,
Levin