module Nyanko
  module UnitProxyProvider
    extend ActiveSupport::Concern

    included do
      extend UnitProxyProvider
      include Helper
    end

    def method_missing(method_name, *args, &block)
      if Array.wrap(Config.proxy_method_name).include?(method_name)
        UnitProxyProvider.class_eval do
          define_method(method_name) do |*_args|
            name = _args.first || Function.current_unit.try(:unit_name)
            if name && unit = Loader.load(name)
              UnitProxy.new(unit, self)
            end
          end
        end
        send(method_name, args.first)
      else
        super
      end
    end
  end
end

module Nyanko
  module UnitProxyProvider
    extend ActiveSupport::Concern

    included do
      extend UnitProxyProvider
      include Helper
    end

    # Define #unit method in this class when #unit is called in first time.
    # Change Config.proxy_method_name if you want to change this method name.
    def method_missing(method_name, *args, &block)
      if Array.wrap(Config.proxy_method_name).include?(method_name)
        UnitProxyProvider.class_eval do
          define_method(method_name) do |*_args|
            name = _args.first || Function.current_unit.try(:unit_name)
            if name && unit = Loader.load(name)
              UnitProxy.new(unit, self)
            end
          end
        end
        send(method_name, args.first)
      else
        super
      end
    end
  end
end

Add code comment for method_missing
Add code comment for method_missing

This method's behavior is a bit difficult.
