Class: NotMonads::Result::Failure

Inherits:
NotMonads::Result show all
Defined in:
lib/not_monads/result.rb

Instance Method Summary collapse

Methods inherited from NotMonads::Result

#initialize

Constructor Details

This class inherits a constructor from NotMonads::Result

Instance Method Details

#==(other) ⇒ Object



70
71
72
# File 'lib/not_monads/result.rb', line 70

def ==(other)
  other.is_a?(self.class) && failure == other.failure
end

#===(other) ⇒ Object



74
75
76
# File 'lib/not_monads/result.rb', line 74

def ===(other)
  other.instance_of?(self.class) && failure === other.failure
end

#failureObject



66
67
68
# File 'lib/not_monads/result.rb', line 66

def failure
  @value
end

#failure?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/not_monads/result.rb', line 41

def failure?
  true
end

#success?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/not_monads/result.rb', line 45

def success?
  false
end

#to_sObject Also known as: inspect



49
50
51
# File 'lib/not_monads/result.rb', line 49

def to_s
  "Failure(#{failure.inspect})"
end

#value!Object

Raises:



54
55
56
# File 'lib/not_monads/result.rb', line 54

def value!
  raise Error, "value! was called on #{self}"
end

#value_or(val = nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/not_monads/result.rb', line 58

def value_or(val = nil)
  if block_given?
    yield
  else
    val
  end
end