class NilClass
  def include?(*args)
    false
  end
end

module MethodPrependAndAppend
  def before_method(m, &blk)
    alias_method :"#{m}_before_extending_before", m
    define_method m do |*args|
      instance_exec(*args, &blk)
      send :"#{m}_before_extending_before", *args
    end
  end

  def after_method(m, &blk)
    alias_method :"#{m}_before_extending_after", m
    define_method m do |*args|
      result = send :"#{m}_before_extending_after", *args
      args.unshift result
      instance_exec(*args, &blk)
    end
  end
end

Class.send :include, MethodPrependAndAppend
