Bobochka
1/6/2016 - 10:38 AM

Instrument methods

Instrument methods

class A
  # move this to concern
  def self.instrument_methods(*methods)
    methods.each do |method|
      define_method "#{method}_with_instrument" do |*args|
        before(method)
        send("#{method}_without_instrument", *args)
        after(method)
      end
    
      alias_method_chain method, :instrument
    end
  end

  def before(method)
    p method
  end

  def after(method)
    p method
  end

  def oh
    p '42'
  end

  def az
    p 'No'
  end

  instrument_methods :oh, :az

end

hatul = A.new

hatul.oh

hatul.az