Class: Spectus::Challenge

Inherits:
Object
  • Object
show all
Defined in:
lib/spectus/challenge.rb

Overview

This class contains a challenge to apply against an object.

Instance Method Summary collapse

Constructor Details

#initialize(method, *args) ⇒ Challenge

Initialize the challenge class.

Parameters:

  • method (#to_sym)

    The identifier of a method.

  • args (Array)

    The arguments of the method.



11
12
13
14
# File 'lib/spectus/challenge.rb', line 11

def initialize(method, *args)
  @method = method.to_sym
  @args   = args
end

Instance Method Details

#to(object) ⇒ BasicObject

Returns The result of the challenge.

Parameters:

  • object (#public_send)

    The subject of the challenge.

Returns:

  • (BasicObject)

    The result of the challenge.



19
20
21
# File 'lib/spectus/challenge.rb', line 19

def to(object)
  object.public_send(@method, *@args)
end

#to_hHash

Properties of the challenge.

Returns:

  • (Hash)

    The properties of the challenge.



26
27
28
29
30
31
# File 'lib/spectus/challenge.rb', line 26

def to_h
  {
    method: @method,
    args:   @args
  }
end