Created
June 12, 2012 15:37
-
-
Save MrJaba/2918267 to your computer and use it in GitHub Desktop.
Wrapping a class method by including a module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Wrapper | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def wrap! | |
class << self | |
alias_method :original_perform, :perform | |
def perform(*args) | |
original_perform(*args) | |
# add in anything you want to do now | |
end | |
end | |
end | |
def singleton_method_added(name) | |
wrap! if name == :perform && !self.respond_to?(:original_perform) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment