Sha256: c7695d901f8dd253522f8d3160d5833c1d2a2bf468b082780d19fe7ac70b229b

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 Bytes

Contents

module Defi
  # This class contains a challenge to apply against an object.
  #
  # @api private
  #
  class Challenge
    # Initialize the challenge class.
    #
    # @api private
    #
    # @param method [#to_sym] The method to send to an object.
    # @param args   [Array]   The arguments of the method.
    def initialize(method, *args)
      @method = method.to_sym
      @args   = args
    end

    # @api public
    #
    # @param object [#object_id] The object to challenge.
    #
    # @return [#object_id] The actual value, or a raised exception.
    def to(object)
      object.public_send(@method, *@args)
    end

    # Properties of the challenge.
    #
    # @api public
    #
    # @return [Hash] The properties of the challenge.
    def to_h
      {
        method: @method,
        args:   @args
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
defi-1.1.3 lib/defi/challenge.rb
defi-1.1.2 lib/defi/challenge.rb
defi-1.1.1 lib/defi/challenge.rb
defi-1.1.0 lib/defi/challenge.rb