module Maybe
Public Class Methods
match(m, just:, nothing:)
click to toggle source
# 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)
click to toggle source
# 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