Sha256: da58dbc1ea44102553344413fc1772e9ba7eea8c5dbf3d51255b523d234f5aa9

Contents?: true

Size: 860 Bytes

Versions: 1

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Decorator
    module Delegator

      def self.included(base)
        base.include Inference
      end

      private

      def method_missing(method_name, *args, **kwargs, &)
        if respond_to_method?(method_name)
          decorator.send(method_name, *args, **kwargs, &)
        else
          super
        end
      end

      def respond_to_method_cache
        @respond_to_method_cache ||= {}
      end

      def respond_to_method?(method_name)
        return respond_to_method_cache[method_name] if respond_to_method_cache.key?(method_name)

        respond_to_method_cache[method_name] = decorator&.public_methods&.include?(method_name)
      end

      def respond_to_missing?(method_name, include_private = false)
        respond_to_method?(method_name) || super
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lite-decorator-2.0.1 lib/lite/decorator/delegator.rb