How to improve a plugin?


I want to add some functionality to a plugin.

The original plugin extends ActiveRecord by including 'ActMethods' ..
I'd like to add some methods to this 'ActMethods' module.

I tried just redefining ActMethods, but then original methods didn't

- - -

So what's the best way to improve functionality of a plugin? I could
write another plugin, but I don't know if that's the best idea :confused:

Yes, that's what I want to do. Extend it without modifying. How do I
do that?

You should use class_eval and instance_eval to do it, not redefining
the class -

For example if you have the class MyClass in the existing plugin and if
you extend and create another plugin Then in the main library file you
can do like

MyClass.class_eval do

  def first_def


etc..... This is only an example Like this you can do

OK this is cool.

Now where should I put this code?

Yes I got it.

But assume we have a Rails project.

I could group all those methods and save them to lib folder.

But where should I add PluginsClass.class_eval line - that one which
would trigger this extending. It doesn't work when I put it into lib.

Place at your inittializers folder.

OK Here's the problem:

The original module is already doing bunch of magic:

def self.included(base)
          base.extend ActMethods

It adds those ActMethods to base. And I just wanna add my methods to
his ActMethods

I can do ActMethods.module_eval def ... end

But I wanna store it in separate module.

Something like

ActMethods.module_eval include MyActMethods doesn't work.

Did you really read the link I posted?

It surely doesn't look like you did.

The correct way of doing it is:

ActMethods.module_eval do
    include MyActMethods

That's what I'm trying to tell - it doesn't work.

When I wrote "ActMethods.module_eval include MyActMethods doesn't

I meant

ActMethods.module_eval do
    include MyActMethods

Just was too lazy to write do/end

And what's the error?

If it's working the other way, just go for it.

Well I'd have to put my whole code into initializer, and that code
belongs to lib, so I would break good rules of code separation.

And I also wanna know why the hell it doesn't work :frowning: