Extending instance-methods of an Module for Plugin-Development

Don’t know if i should write this to rails or ruby mailinglist. But in the case i wan’t to extend the facebooker-plugin without touching it, i will here.

  1. Instance-Methods of modules?

The methods in a module may be instance methods or module methods. Instance methods appear as methods in a class when the module is included, module methods do not. Conversely, module methods may be called without creating an encapsulating object, while instance methods may not. (See Module#module_function)

The method which i wan’t to alias in this case is a method which is listed, when i call:

puts Facebooker::Rails::Helpers.instance_methods

And it’s not listed, when i call:

puts Facebooker::Rails::Helpers.methods

  1. What I wanna do?

I wan’t to extend facebooker with tracking-functionality for our company. For this, i want to write an second plugin which is loaded after it (beginning with a letter higher then F).

In this plugin i wan’t to alias the methods from facebooker like

alias_method :fb_multi_friend_selector_without_awesome, :fb_multi_friend_selector

And write a new method which do the tracking and call the old

Why can’t i do this with:

module Facebooker

module Rails

module Helpers

alias :fb_multi_friend_selector_without_awesome :fb_multi_friend_selector

end

end

end

This should just be a normal plain method!!

This don’t work too:

module Facebooker

module Rails

module Helpers

class << self

alias :fb_multi_friend_selector_without_awesome :fb_multi_friend_selector

end

end

end

end

It seems this possibility just works when there are module-methods.

I have tried the following things, but none of this works (for me):

Facebooker::Rails::Helpers::InstanceMethods.module_eval do

alias_method :fb_multi_friend_selector_without_awesome, :fb_multi_friend_selector

end

(Don’t work because there are no Instance of the Module … )

Theoretically i can Use the Name of the Class which included the model to extend it this way. But for me, without any experience on developing on rails itself it would be easier if i can extend the classes and modules which are only defined in the facebooker-plugin.

Greetings from Germany,

Klaus

Regards kb

http://klausbreyer.de