Skip to content

Instantly share code, notes, and snippets.

@dulao5
Created November 15, 2017 03:30
Show Gist options
  • Save dulao5/ee8b8fe778e80aab4e554bfb1badebe9 to your computer and use it in GitHub Desktop.
Save dulao5/ee8b8fe778e80aab4e554bfb1badebe9 to your computer and use it in GitHub Desktop.
dry_run plugin
class ClassA
class << self
def sendtouser(id, id2)
puts "origin sendtouser #{id} #{id2}"
end
end
end
module DryRunModule
class << self
def plug_dry_run
ClassA.singleton_class.class_eval do
attr_accessor :dry_run
alias_method :original_sendtouser, :sendtouser
def sendtouser(id, id2)
puts "dryrun fun : #{dry_run} :sendtouser #{id} #{id2}"
original_sendtouser(id, id2) unless dry_run
end
end
end
end
end
DryRunModule.plug_dry_run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment