Class: Defi::Challenge
- Inherits:
- BasicObject
- Defined in:
- lib/defi/challenge.rb
Overview
This class contains a challenge to apply against an object.
Instance Method Summary collapse
-
#initialize(method, *args, **opts, &block) ⇒ Challenge
constructor
Initialize the challenge class.
-
#inspect ⇒ String
A string containing a human-readable representation of the challenge.
-
#to(object) ⇒ Defi::Value
The actual value, to raise or to return.
-
#to!(object) ⇒ Defi::Value
The actual value, to raise or to return.
-
#to_h ⇒ Hash
Properties of the challenge.
-
#to_s ⇒ String
String of the challenge.
Constructor Details
#initialize(method, *args, **opts, &block) ⇒ Challenge
Initialize the challenge class.
14 15 16 17 18 19 |
# File 'lib/defi/challenge.rb', line 14 def initialize(method, *args, **opts, &block) @method = method.to_sym @args = args @opts = opts @block = block end |
Instance Method Details
#inspect ⇒ String
A string containing a human-readable representation of the challenge.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/defi/challenge.rb', line 75 def inspect inspected_method = @method.inspect inspected_args = @args.inspect inspected_opts = @opts.inspect inspected_block = @block.nil? ? 'nil' : '<Proc>' 'Defi(' \ "method: #{inspected_method}, " \ "args: #{ inspected_args }, " \ "opts: #{ inspected_opts }, " \ "block: #{ inspected_block }" \ ')' end |
#to(object) ⇒ Defi::Value
Returns The actual value, to raise or to return.
24 25 26 |
# File 'lib/defi/challenge.rb', line 24 def to(object) Value.new { object.public_send(@method, *@args, **@opts, &@block) } end |
#to!(object) ⇒ Defi::Value
Returns The actual value, to raise or to return.
33 34 35 |
# File 'lib/defi/challenge.rb', line 33 def to!(object) ::Aw.fork! { to(object) } end |
#to_h ⇒ Hash
Properties of the challenge.
40 41 42 43 44 45 46 47 |
# File 'lib/defi/challenge.rb', line 40 def to_h { method: @method, args: @args, opts: @opts, block: @block } end |
#to_s ⇒ String
String of the challenge.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/defi/challenge.rb', line 52 def to_s string = ".#{@method}" return string if @args.empty? && @opts.empty? && @block.nil? stringified_args = @args.inspect[1..-2] stringified_opts = @opts.inspect[1..-2] stringified_block = '<Proc>' unless @block.nil? string += '(' stringified_items = [] stringified_items << stringified_args unless @args.empty? stringified_items << stringified_opts unless @opts.empty? stringified_items << stringified_block unless @block.nil? string + stringified_items.join(', ') + ')' end |