mixin a module with initialize

P

pp

[Note: parts of this message were removed to make it a legal post.]


I want to mixin a class, overwrite the initialize method, but I still want to call the original initialize, how can I do this as simple as possible?
class A def initialize #some code endend
module B def initialize #some way to call the original #some other code endend
#then extend
A.include(B)





THANKS
 
A

Andrew Wagner

[Note: parts of this message were removed to make it a legal post.]

Here's a sketch of one approach:

In your module, you'll need to override the module's "self.included" hook.
This gets passed the constant for the class you are being mixed into.

In the included hook, alias the original initialize to some other method
name. Then, create your own initialize method. In the new initialize method,
call the alias to the original initialize method.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top