Class: Mon::Monad::Reactron

Inherits:
React show all
Defined in:
lib/monads/reactron.rb

Overview

The Reactron class represents a changeable value, from which other values can be derived (as Reactrons)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from React

valid?

Methods included from ChainableMonad

#_, #coerce, #method_missing, #respond_to?

Constructor Details

#initialize(obj) ⇒ Reactron

Returns a new instance of Reactron.



61
62
63
# File 'lib/monads/reactron.rb', line 61

def initialize(obj)
  @obj = obj
end

Dynamic Method Handling

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

Class Method Details

.[](obj) ⇒ Object

You should be using React



66
67
68
# File 'lib/monads/reactron.rb', line 66

def self::[] obj
  Reactron.new(obj)
end

Instance Method Details

#<<(obj) ⇒ Object

Change the value of this Reactron



87
88
89
90
# File 'lib/monads/reactron.rb', line 87

def << obj
  @obj = obj
  self
end

#==(o) ⇒ Object



104
105
106
# File 'lib/monads/reactron.rb', line 104

def ==(o)
  eql? o
end

#bind(&fun) ⇒ Object

Apply fun to the value wrapped by this Reactron. Returns a Reactor. Whenever the value is changed (with <<), all derived Reactors are also updated.



73
74
75
# File 'lib/monads/reactron.rb', line 73

def bind &fun
  Reactor[lambda { fun.call(self.unwrap) }]
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
# File 'lib/monads/reactron.rb', line 92

def eql? o
  if o.is_a? React
    @obj == o.unwrap
  else
    @obj == o
  end
end

#equal?(o) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/monads/reactron.rb', line 100

def equal? o
  eql? o
end

#to_sObject



108
109
110
# File 'lib/monads/reactron.rb', line 108

def to_s
  "Reactron[#{ @obj }]"
end

#unwrapObject

Unwrap the value contained by this Reactron



82
83
84
# File 'lib/monads/reactron.rb', line 82

def unwrap
  @obj
end