Class: Rumonade::Some

Inherits:
Option
  • Object
show all
Defined in:
lib/rumonade/option.rb

Overview

Represents an Option containing a value

Constant Summary

Constants included from Monad

Monad::DEFAULT_METHODS_TO_REPLACE_WITH_MONAD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Option

#bind, empty, #get, #get_or_else, #or_nil, unit

Methods included from Monad

#can_flatten_in_monad?, #each, #flat_map_with_monad, #flatten_with_monad, included, #map_with_monad, #select, #shallow_flatten

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



88
89
90
# File 'lib/rumonade/option.rb', line 88

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

:nodoc:



92
93
94
# File 'lib/rumonade/option.rb', line 92

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



99
100
101
# File 'lib/rumonade/option.rb', line 99

def ==(other)
  other.is_a?(Some) && other.value == value
end

#empty?Boolean

Returns true if None, false if Some

Returns:

  • (Boolean)

    Returns true if None, false if Some



95
96
97
# File 'lib/rumonade/option.rb', line 95

def empty?
  false
end

#to_sObject



103
104
105
# File 'lib/rumonade/option.rb', line 103

def to_s
  "Some(#{value.nil? ? 'nil' : value.to_s})"
end