Class: Reac
- Inherits:
-
Object
- Object
- Reac
- Defined in:
- lib/reac/reactivize.rb,
lib/reac.rb,
lib/reac/view.rb,
lib/reac/view/sdl.rb,
lib/reac/view/curses.rb
Overview
Reac::Reactivize
Defined Under Namespace
Modules: Reactivize Classes: Array, Call, CursesView, Proc, SDLView, Value, View
Instance Attribute Summary collapse
-
#last_update ⇒ Object
Returns the value of attribute last_update.
Class Method Summary collapse
-
.value(reac, tick = nil) ⇒ Object
caluculate the value by traversing the tree.
Instance Method Summary collapse
-
#method_missing(method, *args) ⇒ Object
construct tree of Reac::* (instead of call the method) to call it later.
-
#value ⇒ Object
caluculate the value (short-hand for Reac.value(x)).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#last_update ⇒ Object
Returns the value of attribute last_update.
9 10 11 |
# File 'lib/reac.rb', line 9 def last_update @last_update end |
Class Method Details
.value(reac, tick = nil) ⇒ Object
caluculate the value by traversing the tree
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/reac.rb', line 25 def self.value(reac, tick=nil) return reac if not reac.is_a?(Reac) # return cached data if already calculated return reac.data if tick && (reac.last_update == tick) reac.last_update = tick case reac when Value reac.data when Call receiver = Reac.value(reac.receiver, tick) args = reac.args.map{|item| Reac.value(item, tick) } reac.data = receiver.__send__(reac.method, *args) when Proc reac.data = reac.proc.call when Array reac.data = reac.ary.map{|item| Reac.value(item, tick)} else raise "must not happen" end end |