Class: SomeClass
- Inherits:
-
OptionClass
- Object
- OptionClass
- SomeClass
- Defined in:
- lib/option.rb
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
- #error(*argv) ⇒ Object
- #exists?(&blk) ⇒ Boolean
- #filter(&blk) ⇒ Object
- #flat_map(&blk) ⇒ Object
- #flatten ⇒ Object
- #fold(if_empty, &blk) ⇒ Object
- #get ⇒ Object
- #get_or_else(&blk) ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(value) ⇒ SomeClass
constructor
A new instance of SomeClass.
- #inside(&blk) ⇒ Object
- #map(&blk) ⇒ Object
- #or_else(&blk) ⇒ Object
- #or_nil ⇒ Object
- #present? ⇒ Boolean
- #to_a ⇒ Object
Methods inherited from OptionClass
Constructor Details
#initialize(value) ⇒ SomeClass
Returns a new instance of SomeClass.
98 99 100 |
# File 'lib/option.rb', line 98 def initialize(value) @value = value end |
Instance Method Details
#each(&blk) ⇒ Object
114 115 116 117 118 |
# File 'lib/option.rb', line 114 def each(&blk) blk.call(get) nil end |
#empty? ⇒ Boolean
128 129 130 |
# File 'lib/option.rb', line 128 def empty? false end |
#error(*argv) ⇒ Object
172 173 174 |
# File 'lib/option.rb', line 172 def error(*argv) self end |
#exists?(&blk) ⇒ Boolean
144 145 146 |
# File 'lib/option.rb', line 144 def exists?(&blk) !! blk.call(get) end |
#filter(&blk) ⇒ Object
152 153 154 |
# File 'lib/option.rb', line 152 def filter(&blk) exists?(&blk) ? self : None end |
#flat_map(&blk) ⇒ Object
136 137 138 |
# File 'lib/option.rb', line 136 def flat_map(&blk) assert_option(blk.call(get)) end |
#flatten ⇒ Object
165 166 167 168 169 170 |
# File 'lib/option.rb', line 165 def flatten case get when OptionClass then get.flatten else self end end |
#fold(if_empty, &blk) ⇒ Object
140 141 142 |
# File 'lib/option.rb', line 140 def fold(if_empty, &blk) blk.call(get) end |
#get ⇒ Object
106 107 108 |
# File 'lib/option.rb', line 106 def get @value end |
#get_or_else(&blk) ⇒ Object
110 111 112 |
# File 'lib/option.rb', line 110 def get_or_else(&blk) get end |
#include?(value) ⇒ Boolean
148 149 150 |
# File 'lib/option.rb', line 148 def include?(value) get == value end |
#inside(&blk) ⇒ Object
156 157 158 159 |
# File 'lib/option.rb', line 156 def inside(&blk) blk.call(get) self end |
#map(&blk) ⇒ Object
132 133 134 |
# File 'lib/option.rb', line 132 def map(&blk) self.class.new(blk.call(get)) end |
#or_else(&blk) ⇒ Object
161 162 163 |
# File 'lib/option.rb', line 161 def or_else(&blk) self end |
#or_nil ⇒ Object
120 121 122 |
# File 'lib/option.rb', line 120 def or_nil get end |
#present? ⇒ Boolean
124 125 126 |
# File 'lib/option.rb', line 124 def present? true end |
#to_a ⇒ Object
102 103 104 |
# File 'lib/option.rb', line 102 def to_a [get] end |