Sha256: ea56c4f44bd21cfa489a3c0383a1c10c7d38ade8d8f5c515668d86073e7084df

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 Bytes

Contents

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

    def grab(method)
      return [] unless method

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

    private

    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/grabs_original_method_parameters.rb