Initialize a subclass inside a different namespace

J

J2M

have a namespace Foo and a class Bas and a class Bar. I am adding
classes Bas & Bar are both inside the namespace Foo.

module Foo
class Bas
 
T

Trans

J2M said:
have a namespace Foo and a class Bas and a class Bar. I am adding
classes Bas & Bar are both inside the namespace Foo.

module Foo
class Bas
.
end

class Bar
.
end
end

I have some dynamically added classes that are subclasses of Bar, but I
want them to be in a namespace under Foo::Bas e.g. Foo::Bas::ThisClass
& Foo::Bar::ThatClass

class this < Bar
.
end

I put them into the namespace Foo::Bas as follows;

module Foo
class Bas
def self.load_stuff
module_eval File.read(file_name_where_this_class_is_defined)
end
end
end

This all works, but I would like to include some code that runs in the
context of ThisClass but before the contents of
file_name_where_this_class_is_defined, but the catch is I cannot assume
the names of the classes being loaded from the file, therefore I am
looking for a callback that is run in context of ThisClass as soon as
ThisClass is defined.

Any ideas?

You might try #inherited.

T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top