Class: SomeClass

Inherits:
OptionClass show all
Defined in:
lib/option.rb

Instance Method Summary collapse

Methods inherited from OptionClass

#==, [], #match

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

Returns:

  • (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

Returns:

  • (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

#flattenObject



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

#getObject



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

Returns:

  • (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_nilObject



120
121
122
# File 'lib/option.rb', line 120

def or_nil
  get
end

#present?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/option.rb', line 124

def present?
  true
end

#to_aObject



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

def to_a
  [get]
end