Class: Monads::Eventually

Inherits:
Object
  • Object
show all
Includes:
Monad
Defined in:
lib/monads/eventually.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Monad

#method_missing, #within

Constructor Details

#initialize(&block) ⇒ Eventually

Returns a new instance of Eventually.



9
10
11
# File 'lib/monads/eventually.rb', line 9

def initialize(&block)
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Monads::Monad

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/monads/eventually.rb', line 7

def block
  @block
end

Class Method Details

.from_value(value) ⇒ Object



31
32
33
34
35
# File 'lib/monads/eventually.rb', line 31

def self.from_value(value)
  Eventually.new do |success|
    success.call(value)
  end
end

Instance Method Details

#and_then(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/monads/eventually.rb', line 17

def and_then(&block)
  block = ensure_monadic_result(&block)

  Eventually.new do |success|
    run do |value|
      block.call(value).run(&success)
    end
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/monads/eventually.rb', line 27

def respond_to_missing?(method_name, include_private = false)
  super || run { |value| value.respond_to?(method_name, include_private) }
end

#run(&success) ⇒ Object



13
14
15
# File 'lib/monads/eventually.rb', line 13

def run(&success)
  block.call(success)
end