Class: Rumonade::Some
Overview
Represents an Option containing a value
Constant Summary
Constants included from Monad
Monad::DEFAULT_METHODS_TO_REPLACE_WITH_MONAD
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#empty? ⇒ Boolean
Returns
true
ifNone
,false
ifSome
. -
#initialize(value) ⇒ Some
constructor
A new instance of Some.
- #to_s ⇒ Object
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
#value ⇒ Object (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
95 96 97 |
# File 'lib/rumonade/option.rb', line 95 def empty? false end |
#to_s ⇒ Object
103 104 105 |
# File 'lib/rumonade/option.rb', line 103 def to_s "Some(#{value.nil? ? 'nil' : value.to_s})" end |