#!/usr/bin/env ruby

require 'pry'

class Foo
  def bar
    puts "old_bar"
    2
  end
end


class Module
  def do_override(meth, name, &blk)
    @@override ||= {}
    @@override[:meth] ||= []
    class_exec(instance_method(meth)) do |mv|
      define_method(meth) do |*args|
        blk.call(mv.bind(self), *args)
      end
    end
    @@override[:meth] << name
  end

  def get_override_list(meth)
    return [] unless @@override
    @@override[:meth] || []
  end
end


#Foo.class_exec(Foo.instance_method(:bar)) do |v|
#  puts "Extending bar method"
#  define_method(:bar) do
#    puts "new_bar"
#    v.bind(self).call + 1
#  end # define_method
#end


binding.pry