Sha256: e1f3a6c1b9524789092747644da7149aac886c07e87257d74b9ad0b035334b52

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

# typed: strict

module Mocktail
  class GrabsOriginalMethodParameters
    extend T::Sig

    # Sorbet wraps the original method in a sig wrapper, so we need to unwrap it.
    # The value returned from `owner.instance_method(method_name)` does not have
    # the real parameters values available, as they'll have been erased
    #
    # If the method isn't wrapped by Sorbet, this will return the #instance_method,
    # per usual
    sig { params(method: T.nilable(T.any(UnboundMethod, Method))).returns(T::Array[T::Array[Symbol]]) }
    def grab(method)
      return [] unless method

      if (wrapped_method = sorbet_wrapped_method(method))
        wrapped_method.parameters
      else
        method.parameters
      end
    end

    private

    sig { params(method: T.any(UnboundMethod, Method)).returns(T.nilable(T::Private::Methods::Signature)) }
    def sorbet_wrapped_method(method)
      return unless defined?(::T::Private::Methods)

      T::Private::Methods.signature_for_method(method)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocktail-2.0.0 lib/mocktail/sorbet/mocktail/grabs_original_method_parameters.rb