Class: Defi::Challenge Private
- Inherits:
- BasicObject
- Defined in:
- lib/defi/challenge.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class contains a challenge to apply against an object.
Instance Method Summary collapse
-
#initialize(method, *args, **opts, &block) ⇒ Challenge
constructor
private
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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the challenge class.
19 20 21 22 23 24 |
# File 'lib/defi/challenge.rb', line 19 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.
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/defi/challenge.rb', line 90 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.
31 32 33 |
# File 'lib/defi/challenge.rb', line 31 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.
42 43 44 |
# File 'lib/defi/challenge.rb', line 42 def to!(object) ::Aw.fork! { to(object) } end |
#to_h ⇒ Hash
Properties of the challenge.
51 52 53 54 55 56 57 58 |
# File 'lib/defi/challenge.rb', line 51 def to_h { method: @method, args: @args, opts: @opts, block: @block } end |
#to_s ⇒ String
String of the challenge.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/defi/challenge.rb', line 65 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 |