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:



305
306
307
# File 'lib/fear/try.rb', line 305

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

#Success(value) ⇒ Success

Parameters:

  • value (any)

Returns:



312
313
314
# File 'lib/fear/try.rb', line 312

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:



298
299
300
# File 'lib/fear/try.rb', line 298

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