class Defi::Value
This class contains an object that returned or raised during the initialize.
Attributes
object[R]
@return [#object_id] The returned or the raised object.
Public Class Methods
new() { || ... }
click to toggle source
Initialize the value class.
@yieldreturn [#object_id] The challenged code. rubocop:disable Lint/RescueException
# File lib/defi/value.rb, line 14 def initialize @object = yield @raised = false rescue ::Exception => e @object = e @raised = true end
Public Instance Methods
call()
click to toggle source
Raise or return the value.
@return [#object_id] Raised exception or returned object.
# File lib/defi/value.rb, line 26 def call raise object if raised? object end
inspect()
click to toggle source
A string containing a human-readable representation of the value.
@return [String] The human-readable representation of the value.
# File lib/defi/value.rb, line 57 def inspect "Value(object: #{object}, raised: #{raised?})" end
raised?()
click to toggle source
@return [Boolean] The value was raised (or returned)?
# File lib/defi/value.rb, line 33 def raised? @raised end
to_h()
click to toggle source
Properties of the value.
@return [Hash] The properties of the value.
# File lib/defi/value.rb, line 40 def to_h { raised: raised?, object: object } end
to_s()
click to toggle source
String of the value.
@return [String] The string representation of the value.
# File lib/defi/value.rb, line 50 def to_s "#{raise_or_return} #{object}" end
Private Instance Methods
raise_or_return()
click to toggle source
@return [String] A “raise” or “return” string.
# File lib/defi/value.rb, line 64 def raise_or_return raised? ? "raise" : "return" end