Class: Defi::Value
- Inherits:
-
Object
- Object
- Defi::Value
- Defined in:
- lib/defi/value.rb
Overview
This class contains an object that returned or raised during the initialize.
Instance Attribute Summary collapse
-
#object ⇒ #object_id
readonly
The returned or the raised object.
Instance Method Summary collapse
-
#call ⇒ #object_id
Raise or return the value.
-
#initialize ⇒ 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 ⇒ Value
Initialize the value class.
rubocop:disable Lint/RescueException
14 15 16 17 18 19 20 |
# File 'lib/defi/value.rb', line 14 def initialize @object = yield @raised = false rescue ::Exception => e @object = e @raised = true end |
Instance Attribute Details
#object ⇒ #object_id (readonly)
Returns The returned or the raised object.
8 9 10 |
# File 'lib/defi/value.rb', line 8 def object @object end |
Instance Method Details
#call ⇒ #object_id
Raise or return the value.
26 27 28 29 30 |
# File 'lib/defi/value.rb', line 26 def call raise object if raised? object end |
#inspect ⇒ String
A string containing a human-readable representation of the value.
58 59 60 |
# File 'lib/defi/value.rb', line 58 def inspect "Value(object: #{object}, raised: #{raised?})" end |
#raised? ⇒ Boolean
Returns The value was raised (or returned)?.
33 34 35 |
# File 'lib/defi/value.rb', line 33 def raised? @raised end |
#to_h ⇒ Hash
Properties of the value.
40 41 42 43 44 45 |
# File 'lib/defi/value.rb', line 40 def to_h { raised: raised?, object: object } end |
#to_s ⇒ String
String of the value.
50 51 52 53 |
# File 'lib/defi/value.rb', line 50 def to_s string = raised? ? 'raise' : 'return' "#{string} #{object}" end |