Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Created August 25, 2011 13:31
Show Gist options
  • Save d11wtq/1170661 to your computer and use it in GitHub Desktop.
Save d11wtq/1170661 to your computer and use it in GitHub Desktop.
Example of wrapping methods using mixins (more complicated than it should be)
module VerboseJob
module ClassMethods
def wrap_perform!
class << self
def perform_with_verbose(*args)
JobLogger.verbose { perform_without_verbose(*args) }
end
alias_method_chain :perform, :verbose \
unless instance_method(:perform) == instance_method(:perform_with_verbose)
end
end
def singleton_method_added(name)
wrap_perform! if name == :perform
end
end
def self.included(job_class)
job_class.extend ClassMethods
job_class.wrap_perform! if job_class.respond_to?(:perform)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment