Is it possible to generate a class at run-time and return it?
···
----- Original Message -----
Not exactly sure what you are looking for, but maybe this will help you? If
not, could you give a little more information about what you want your
auto-generated class to look like?
Instead of:
class Foo < Bar
end
you could try:
Foo = Class.new Bar
Class names are just constants, after all. If you want it to be anonymous,
just don’t set it to Foo.
Of course, you could always generate the Ruby code you want in a string, and
eval that, but there are usually easier ways to do what you want.
Is it possible to generate a class at run-time and return it?
Not exactly sure what you are looking for, but maybe this will help you? If
not, could you give a little more information about what you want your
auto-generated class to look like?
What you wrote helps, I think. I’ll try to implement it. But to answer your
question, this is what I want:
I put together a Polynomial class. You can use it like this:
After I’ve done some more work, I’d like to extend this so that it works over any
ring (not just real numbers). I think that it would be neat.
I also thought that I could make a Frac() class that gives you the fraction field
of a ring (class). For instance, Frac(Integer) would be the same thing as
Rational.
If I define a similar Polynomial, I could use Frac(Polynomial(Integer)) to define
a class whose elements are of form p(x)/q(x)
I don’t know how I would do this. I was just investigating the possibility.
···
----- Original Message -----
–
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137