module Fear::Try::Mixin
Include this mixin to access convenient factory methods. @example
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>
Public Instance Methods
Failure(exception)
click to toggle source
@param exception [StandardError] @return [Failure]
# File lib/fear/try.rb, line 307 def Failure(exception) Fear.failure(exception) end
Success(value)
click to toggle source
@param value [any] @return [Success]
# File lib/fear/try.rb, line 314 def Success(value) Fear.success(value) end
Try(&block)
click to toggle source
Constructs a Try
using the block. This method ensures any non-fatal exception is caught and a Failure
object is returned. @return [Try]
# File lib/fear/try.rb, line 300 def Try(&block) Fear.try(&block) end