Module: Hopscotch::Error

Extended by:
Error
Included in:
Error
Defined in:
lib/hopscotch/error.rb

Overview

‘Error` provides helper functions for working with ErrorValue (and thus ReturnValue)

Instance Method Summary collapse

Instance Method Details

#error?(e) ⇒ Boolean

Returns ‘true` if `e` is an error

Returns:

  • (Boolean)


20
21
22
# File 'lib/hopscotch/error.rb', line 20

def error?(e)
  ErrorValue === e
end

#success?(e) ⇒ Boolean

Returns ‘false` if `e` is an error

Returns:

  • (Boolean)


25
26
27
# File 'lib/hopscotch/error.rb', line 25

def success?(e)
  ! error?(e)
end

#to_error(e) ⇒ Object

Convert ‘e` into a value representing an error, if required.



30
31
32
33
34
35
36
37
# File 'lib/hopscotch/error.rb', line 30

def to_error(e)
  case e
  when ErrorValue
    e
  else
    ErrorValue.new(e)
  end
end