Module: Fear::TryApi
- Included in:
- Fear
- Defined in:
- lib/fear/try_api.rb
Instance Method Summary collapse
- #failure(exception) ⇒ Fear::Failure
- #success(value) ⇒ Fear::Success
-
#try ⇒ Fear::Try
Constructs a
Try
using the block.
Instance Method Details
#failure(exception) ⇒ Fear::Failure
22 23 24 |
# File 'lib/fear/try_api.rb', line 22 def failure(exception) Fear::Failure.new(exception) end |
#success(value) ⇒ Fear::Success
29 30 31 |
# File 'lib/fear/try_api.rb', line 29 def success(value) Fear::Success.new(value) end |
#try ⇒ Fear::Try
Constructs a Try
using the block. This method ensures any non-fatal exception is caught and a Failure
object is returned.
13 14 15 16 17 |
# File 'lib/fear/try_api.rb', line 13 def try success(yield) rescue StandardError => error failure(error) end |