Sha256: ad3fbb9aec70537d68de1d8c371089106fa148356648ad98606315ae733a19cf

Contents?: true

Size: 678 Bytes

Versions: 3

Compression:

Stored size: 678 Bytes

Contents

# frozen_string_literal: true

module Kind
  module Try
    extend self

    def call(*args)
      object = args.shift

      call!(object, args.shift, args)
    end

    def self.[](*args)
      method_name = args.shift

      ->(object) { call!(object, method_name, args) }
    end

    def call!(object, method_name, args) # :nodoc
      return if KIND.null?(object)

      resolve(object, method_name, args)
    end

    private

      def resolve(object, method_name, args = Empty::ARRAY)
        return unless object.respond_to?(method_name)
        return object.public_send(method_name) if args.empty?

        object.public_send(method_name, *args)
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kind-5.1.0 lib/kind/core/try.rb
kind-5.0.0 lib/kind/try.rb
kind-4.1.0 lib/kind/try.rb