Class: Defi::Value Private
- Inherits:
-
Object
- Object
- Defi::Value
- Defined in:
- lib/defi/value.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 an object that returned or raised during the initialize.
Instance Attribute Summary collapse
-
#object ⇒ #object_id
readonly
private
The returned or the raised object.
Instance Method Summary collapse
-
#call ⇒ #object_id
private
Raise or return the value.
-
#initialize(&block) ⇒ Value
constructor
Initialize the value class.
-
#inspect ⇒ String
A string containing a human-readable representation of the value.
-
#raised? ⇒ Boolean
The value was raised (or returned)?.
-
#to_h ⇒ Hash
Properties of the value.
-
#to_s ⇒ String
String of the value.
Constructor Details
#initialize(&block) ⇒ Value
Initialize the value class.
rubocop:disable Lint/RescueException
18 19 20 21 22 23 24 |
# File 'lib/defi/value.rb', line 18 def initialize(&block) @object = block.call @raised = false rescue ::Exception => e @object = e @raised = true end |
Instance Attribute Details
#object ⇒ #object_id (readonly)
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.
Returns The returned or the raised object.
10 11 12 |
# File 'lib/defi/value.rb', line 10 def object @object end |
Instance Method Details
#call ⇒ #object_id
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.
Raise or return the value.
30 31 32 33 34 |
# File 'lib/defi/value.rb', line 30 def call raise object if raised? object end |
#inspect ⇒ String
A string containing a human-readable representation of the value.
75 76 77 |
# File 'lib/defi/value.rb', line 75 def inspect "Value(object: #{object}, raised: #{raised?})" end |
#raised? ⇒ Boolean
Returns The value was raised (or returned)?.
39 40 41 |
# File 'lib/defi/value.rb', line 39 def raised? @raised end |
#to_h ⇒ Hash
Properties of the value.
48 49 50 51 52 53 |
# File 'lib/defi/value.rb', line 48 def to_h { raised: raised?, object: object } end |
#to_s ⇒ String
String of the value.
60 61 62 63 64 65 66 67 68 |
# File 'lib/defi/value.rb', line 60 def to_s string = if raised? 'raise' else 'return' end "#{string} #{object}" end |