Skip to content

Instantly share code, notes, and snippets.

@MrJaba
Created June 12, 2012 15:37
Show Gist options
  • Save MrJaba/2918267 to your computer and use it in GitHub Desktop.
Save MrJaba/2918267 to your computer and use it in GitHub Desktop.
Wrapping a class method by including a module
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