Module: Option

Includes:
Enumerable
Included in:
None, Some
Defined in:
lib/optional/option.rb,
lib/optional/option/match.rb,
lib/optional/option/errors.rb,
lib/optional/option/enumerable.rb

Defined Under Namespace

Modules: Enumerable Classes: BadMatchError, Match, ValueOfNoneError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#detect, #flat_map, #flatten, #grep, #juxt, #map, #map_through, #reduce, #reject, #select, #to_ary

Class Method Details

.[](value) ⇒ Object



4
5
6
# File 'lib/optional/option.rb', line 4

def self.[] value
  value.nil? ? None : Some[value]
end

Instance Method Details

#match(&block) ⇒ Object



8
9
10
# File 'lib/optional/option.rb', line 8

def match(&block)
  Match.new.tap { |m| block.call(m) }.evaluate(self)
end