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.
25 26 27 |
# File 'lib/option.rb', line 25 def initialize(value) @value = value end |
Instance Method Details
#each(&blk) ⇒ Object
41 42 43 44 45 |
# File 'lib/option.rb', line 41 def each(&blk) blk.call(get) nil end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/option.rb', line 55 def empty? false end |
#error(*argv) ⇒ Object
99 100 101 |
# File 'lib/option.rb', line 99 def error(*argv) self end |
#exists?(&blk) ⇒ Boolean
71 72 73 |
# File 'lib/option.rb', line 71 def exists?(&blk) !! blk.call(get) end |
#filter(&blk) ⇒ Object
79 80 81 |
# File 'lib/option.rb', line 79 def filter(&blk) exists?(&blk) ? self : None end |
#flat_map(&blk) ⇒ Object
63 64 65 |
# File 'lib/option.rb', line 63 def flat_map(&blk) assert_option(blk.call(get)) end |
#flatten ⇒ Object
92 93 94 95 96 97 |
# File 'lib/option.rb', line 92 def flatten case get when OptionClass then get.flatten else self end end |
#fold(if_empty, &blk) ⇒ Object
67 68 69 |
# File 'lib/option.rb', line 67 def fold(if_empty, &blk) blk.call(get) end |
#get ⇒ Object
33 34 35 |
# File 'lib/option.rb', line 33 def get @value end |
#get_or_else(&blk) ⇒ Object
37 38 39 |
# File 'lib/option.rb', line 37 def get_or_else(&blk) get end |
#include?(value) ⇒ Boolean
75 76 77 |
# File 'lib/option.rb', line 75 def include?(value) get == value end |
#inside(&blk) ⇒ Object
83 84 85 86 |
# File 'lib/option.rb', line 83 def inside(&blk) blk.call(get) self end |
#map(&blk) ⇒ Object
59 60 61 |
# File 'lib/option.rb', line 59 def map(&blk) self.class.new(blk.call(get)) end |
#or_else(&blk) ⇒ Object
88 89 90 |
# File 'lib/option.rb', line 88 def or_else(&blk) self end |
#or_nil ⇒ Object
47 48 49 |
# File 'lib/option.rb', line 47 def or_nil get end |
#present? ⇒ Boolean
51 52 53 |
# File 'lib/option.rb', line 51 def present? true end |
#to_a ⇒ Object
29 30 31 |
# File 'lib/option.rb', line 29 def to_a [get] end |