module T::Private::ClassUtils

def self.def_with_visibility(mod, name, visibility, method=nil, &block)

def self.def_with_visibility(mod, name, visibility, method=nil, &block)
  mod.module_exec do
    # Start a visibility (public/protected/private) region, so that
    # all of the method redefinitions happen with the right visibility
    # from the beginning. This ensures that any other code that is
    # triggered by `method_added`, sees the redefined method with the
    # right visibility.
    send(visibility)
    if method
      define_method(name, method)
    else
      define_method(name, &block)
    end
    if block && block.arity < 0 && respond_to?(:ruby2_keywords, true)
      ruby2_keywords(name)
    end
  end
end