Class: Mon::Monad::Reactron
Overview
The Reactron class represents a changeable value, from which other values can be derived (as Reactrons)
Class Method Summary collapse
-
.[](obj) ⇒ Object
You should be using React.
Instance Method Summary collapse
-
#<<(obj) ⇒ Object
Change the value of this Reactron.
- #==(o) ⇒ Object
-
#bind(&fun) ⇒ Object
Apply fun to the value wrapped by this Reactron.
- #eql?(o) ⇒ Boolean
- #equal?(o) ⇒ Boolean
-
#initialize(obj) ⇒ Reactron
constructor
A new instance of Reactron.
- #to_s ⇒ Object
-
#unwrap ⇒ Object
Unwrap the value contained by this Reactron.
Methods inherited from React
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
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
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
100 101 102 |
# File 'lib/monads/reactron.rb', line 100 def equal? o eql? o end |
#to_s ⇒ Object
108 109 110 |
# File 'lib/monads/reactron.rb', line 108 def to_s "Reactron[#{ @obj }]" end |
#unwrap ⇒ Object
Unwrap the value contained by this Reactron
82 83 84 |
# File 'lib/monads/reactron.rb', line 82 def unwrap @obj end |