Class: Monadic::Just

Inherits:
Maybe show all
Defined in:
lib/monadic/maybe.rb

Overview

Represents an existing value

Defined Under Namespace

Classes: Proxy

Instance Method Summary collapse

Methods inherited from Maybe

#empty?, #select, #truly?, unit

Methods included from Monad

#==, #bind, #flat_map, #initialize, #join, #map, #to_ary, #to_s

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object


43
44
45
# File 'lib/monadic/maybe.rb', line 43

def method_missing(m, *args)
  Maybe(@value.__send__(m, *args))
end

Instance Method Details

#fetch(default = nil) ⇒ Object Also known as: _

Returns the underlying value.

Returns:

  • the underlying value


38
39
40
# File 'lib/monadic/maybe.rb', line 38

def fetch(default=nil)
  @value
end

#or(other) ⇒ Object

Returns always self for Just.

Returns:

  • always self for Just


66
67
68
# File 'lib/monadic/maybe.rb', line 66

def or(other)
  self
end

#proxyObject


61
62
63
# File 'lib/monadic/maybe.rb', line 61

def proxy
  @proxy ||= Proxy.new(self)
end