Class: Hibiki::Derived
- Inherits:
-
Object
- Object
- Hibiki::Derived
- Defined in:
- lib/hibiki/derived.rb
Overview
---- derived / computed -----------------------------------------------------
Instance Method Summary collapse
-
#call ⇒ Object
Solid signals are getter functions;
sig.()reads (and registers). -
#initialize(&block) ⇒ Derived
constructor
A new instance of Derived.
- #inspect ⇒ Object
- #invalidate ⇒ Object
-
#peek ⇒ Object
Read without subscribing the reader.
- #to_s ⇒ Object
- #value ⇒ Object
Methods included from Observer
#add_source, #clear_sources, #sources
Methods included from Trackable
#notify, #register_dependency, #subscribers, #unsubscribe
Constructor Details
#initialize(&block) ⇒ Derived
Returns a new instance of Derived.
9 10 11 12 |
# File 'lib/hibiki/derived.rb', line 9 def initialize(&block) @block = block @dirty = true end |
Instance Method Details
#call ⇒ Object
Solid signals are getter functions; sig.() reads (and registers).
28 |
# File 'lib/hibiki/derived.rb', line 28 def call = value |
#inspect ⇒ Object
38 |
# File 'lib/hibiki/derived.rb', line 38 def inspect = "#<Hibiki::Derived #{@dirty ? 'dirty' : @value.inspect}>" |
#invalidate ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hibiki/derived.rb', line 30 def invalidate return if @dirty @dirty = true notify # propagate dirtiness downstream (derived-of-derived, effects) end |
#peek ⇒ Object
Read without subscribing the reader. A dirty derived still recomputes (collecting its own deps as usual) — peek only skips the outward edge.
22 23 24 25 |
# File 'lib/hibiki/derived.rb', line 22 def peek recompute if @dirty @value end |
#to_s ⇒ Object
37 |
# File 'lib/hibiki/derived.rb', line 37 def to_s = value.to_s |
#value ⇒ Object
14 15 16 17 18 |
# File 'lib/hibiki/derived.rb', line 14 def value recompute if @dirty register_dependency @value end |