class ReSorcery::Maybe::Just

Public Class Methods

new(value) click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 11
def initialize(value)
  @value = value
end

Public Instance Methods

==(other) click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 38
def ==(other)
  other.class == Just && other.instance_eval { @value } == @value
end
and_then(&block) click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 15
def and_then(&block)
  ArgCheck['block', block.call(@value), Just, Nothing]
end
as_json(*) click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 42
def as_json(*)
  {
    kind: :just,
    value: @value,
  }
end
assign(name, &block) click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 31
def assign(name, &block)
  raise Error::NonHashAssignError, @value unless @value.is_a?(Hash)

  ArgCheck['block', block.call(@value), Just, Nothing]
    .map { |k| @value.merge(name => k) }
end
get_or_else() click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 27
def get_or_else
  @value
end
map(&block) click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 19
def map(&block)
  Just.new(block.call(@value))
end
or_else() click to toggle source
# File lib/re_sorcery/maybe/just.rb, line 23
def or_else
  self
end