class Mon::Monad::Some
The Some
class represents a value that is NOT null/false
Public Class Methods
Protected Class Methods
new(obj)
click to toggle source
Calls superclass method
# File lib/monads/maybe.rb, line 62 def initialize(obj) @obj = obj super() end
Public Instance Methods
==(o)
click to toggle source
# File lib/monads/maybe.rb, line 127 def ==(o) eql?(o) end
bind(&fun)
click to toggle source
eql?(other)
click to toggle source
# File lib/monads/maybe.rb, line 119 def eql?(other) if other.is_a? Some @obj == other.unwrap else @obj == other end end
equal?(o)
click to toggle source
# File lib/monads/maybe.rb, line 131 def equal?(o) eql?(o) end
or(obj = nil, &f)
click to toggle source
orFail(msg = nil)
click to toggle source
Get the value, or throw an exception (using the optional supplied msg) if it's empty
# File lib/monads/maybe.rb, line 98 def orFail(msg = nil) msg = "No such value!" if msg.nil? self::or { throw RuntimeError.new(msg) } end
to_s()
click to toggle source
# File lib/monads/maybe.rb, line 115 def to_s "Some[#{ @obj.to_s }]" end
Protected Instance Methods
_canBind?(name)
click to toggle source
# File lib/monads/maybe.rb, line 83 def _canBind? name @obj.respond_to? name end
unwrap()
click to toggle source
Unwrap the wrapped value, nil or not
# File lib/monads/maybe.rb, line 79 def unwrap @obj end