Module: Fear::Try::Mixin

Included in:
Mixin
Defined in:
lib/fear/try.rb

Overview

Include this mixin to access convenient factory methods.

Examples:

include Fear::Try::Mixin

Fear.try { 4/2 } #=> #<Fear::Success value=2>
Fear.try { 4/0 } #=> #<Fear::Failure exception=#<ZeroDivisionError: divided by 0>>
Fear.success(2)  #=> #<Fear::Success value=2>

Instance Method Summary collapse

Instance Method Details

#Failure(exception) ⇒ Failure

Parameters:

  • exception (StandardError)

Returns:



307
308
309
# File 'lib/fear/try.rb', line 307

def Failure(exception)
  Fear.failure(exception)
end

#Success(value) ⇒ Success

Parameters:

  • value (any)

Returns:



314
315
316
# File 'lib/fear/try.rb', line 314

def Success(value)
  Fear.success(value)
end

#Try(&block) ⇒ Try

Constructs a Try using the block. This method ensures any non-fatal exception is caught and a Failure object is returned.

Returns:



300
301
302
# File 'lib/fear/try.rb', line 300

def Try(&block)
  Fear.try(&block)
end