Class: NotMonads::Result::Failure

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

Instance Attribute Summary

Attributes inherited from NotMonads::Result

#failure, #success

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Failure

Returns a new instance of Failure.



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

def initialize(value)
  super()
  @failure = value
end

Instance Method Details

#==(other) ⇒ Object



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

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

#===(other) ⇒ Object



78
79
80
# File 'lib/not_monads/result.rb', line 78

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

#failure?Boolean

Returns:

  • (Boolean)


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

def failure?
  true
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  false
end

#to_sObject Also known as: inspect



57
58
59
# File 'lib/not_monads/result.rb', line 57

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

#value!Object

Raises:



62
63
64
# File 'lib/not_monads/result.rb', line 62

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

#value_or(val = nil) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/not_monads/result.rb', line 66

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