views:

41

answers:

2

Hi,

I am using facebooker in one of my applications. I want to add some application specific methods to various classes in it? e.g.

In facebooker/lib/facebooker/models/user.rb

module Facebooker
  class User
    # I want to add my methods here. for e.g my_method
  end
end

I can not directly put my_method in the plugin itself since I also want to access my models from there. Not defining the methods in plugin code itself will also be helpful when I upgrade.

A: 

try monkeypatching the facebooker plugin inside the model you are using it in, that way your edits only affect code inside the model you are wanting your edits to work in

imightbeinatree at Cloudspace
+1  A: 

Somewhere in the file you wish to use my_method, type in, include, or require the following code:

module Facebooker
  class User
    def my_method
        #whatever
    end
  end
end

Ruby will then add my_method to Facebooker's User class before you need to call it.

Ryan