Class: MaybeMonad::Monad

Inherits:
Object show all
Defined in:
lib/maybe_monad.rb

Instance Method Summary collapse

Constructor Details

#initialize(just) ⇒ Monad



17
18
19
# File 'lib/maybe_monad.rb', line 17

def initialize(just) 
  @just = just 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/maybe_monad.rb', line 25

def method_missing(name, *args) 
  # default, nil don't respond to any method
  @just.nil? ? Monad.new(nil) : Monad.new(@just.__send__(name, *args)) 

  ## extra, nil respond to methods that can respond
  #@just.respond_to?(name) ? Monad.new(@just.__send__(name, *args)) : Monad.new(nil) 
end

Instance Method Details

#justObject



21
22
23
# File 'lib/maybe_monad.rb', line 21

def just 
  @just 
end