class Some
Represents a non-empty value
Public Class Methods
new(value)
click to toggle source
# File lib/indubitably.rb, line 57 def initialize(value) @value = value end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
Maybe#==
# File lib/indubitably.rb, line 97 def ==(other) super && get == other.get end
Also aliased as: eql?
===(other)
click to toggle source
# File lib/indubitably.rb, line 102 def ===(other) other && other.class == self.class && @value === other.get end
get()
click to toggle source
# File lib/indubitably.rb, line 61 def get @value end
if_some(val = nil, &blk)
click to toggle source
# File lib/indubitably.rb, line 69 def if_some(val = nil, &blk) Maybe(val.nil? ? blk.call : val) end
is_none?()
click to toggle source
# File lib/indubitably.rb, line 78 def is_none? false end
is_some?()
click to toggle source
rubocop:disable PredicateName
# File lib/indubitably.rb, line 74 def is_some? true end
join()
click to toggle source
rubocop:enable PredicateName
# File lib/indubitably.rb, line 83 def join @value.is_a?(Maybe) ? @value : self end
join!()
click to toggle source
# File lib/indubitably.rb, line 87 def join! if @value.is_a?(Some) @value.join! elsif @value.is_a?(None) @value else self end end
method_missing(method_sym, *args, &block)
click to toggle source
This strips the leading underscore if the method is sent with that prefix; this allows us to force dispatch to the contained object. It is inline in two places because this avoids a function call performance hit.
# File lib/indubitably.rb, line 109 def method_missing(method_sym, *args, &block) method_sym = method_sym.slice(1, method_sym.length) if method_sym[0] == "_" map { |value| value.send(method_sym, *args, &block) } end
or_else(*)
click to toggle source
# File lib/indubitably.rb, line 65 def or_else(*) @value end
Private Instance Methods
__enumerable_value()
click to toggle source
# File lib/indubitably.rb, line 116 def __enumerable_value [@value] end