class Mon::Monad::Success
Public Class Methods
[](obj)
click to toggle source
# File lib/monads/try.rb, line 58 def self.[](obj) if (obj.is_a? Failure) or (obj.is_a? Success) obj else Success.new(obj) end end
valid?(o)
click to toggle source
# File lib/monads/try.rb, line 110 def self::valid?(o) o.is_a? self.class end
Protected Class Methods
new(obj)
click to toggle source
Calls superclass method
# File lib/monads/try.rb, line 49 def initialize(obj) if obj.is_a? Success @obj = obj.get else @obj = obj end super() end
Public Instance Methods
==(o)
click to toggle source
# File lib/monads/try.rb, line 98 def ==(o) eql?(o) end
bind(&fun)
click to toggle source
# File lib/monads/try.rb, line 66 def bind &fun begin Success[fun.call(@obj)] rescue StandardError => e Failure[e] end end
eql?(other)
click to toggle source
# File lib/monads/try.rb, line 90 def eql?(other) if other.is_a? Success @obj == other.unwrap else @obj == other end end
equal?(o)
click to toggle source
# File lib/monads/try.rb, line 102 def equal?(o) eql?(o) end
or(obj, &f)
click to toggle source
# File lib/monads/try.rb, line 78 def or obj, &f @obj end
orFail()
click to toggle source
# File lib/monads/try.rb, line 82 def orFail @obj end
to_s()
click to toggle source
# File lib/monads/try.rb, line 106 def to_s "Success[#{@obj}]" end
Protected Instance Methods
_canBind?(name)
click to toggle source
# File lib/monads/try.rb, line 74 def _canBind?(name) @obj.respond_to? name end
unwrap()
click to toggle source
# File lib/monads/try.rb, line 86 def unwrap @obj end