Module: Maybe
- Defined in:
- lib/maybe.rb
Defined Under Namespace
Class Method Summary collapse
Class Method Details
.match(m, just:, nothing:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/maybe.rb', line 17 def self.match(m, just:, nothing:) if m.is_just? just.call(m.send(:val)) elsif m.is_nothing? if nothing.is_a? Proc nothing.call else nothing end end end |
.new(&block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/maybe.rb', line 4 def self.new(&block) val = begin block.call() rescue Exception => e e end if val.nil? || val.is_a?(Exception) Nothing.new else Just.new val end end |