I have a network of nodes, each node influencing the state of some other nodes (imagine an Excel spreadsheet with cells values depending on other cells through formulas).
I'm wondering what is the cleanest way to implement this in Ruby ?
Of course I could have one process per node, but how will it perform if the number of nodes increases ? And, I'm sure there are libraries for that, but I can't find a up-to-date one.
Thanks for your help !
Update: Sounds like EventMachine might do the job... but it seems more adapted to a small number of "nodes"
This sounds like a good situation for the observer pattern. This is a sample of that in ruby:
Notice how the value of
SumNode
isn't recalculated every time it is requested - instead it is updated when one of its value nodes is updated. This works recursively, so that innerSumNodes
also trigger updates. As the notification includes the uniqueid
of the node, it is possible to write more complexNode
types, such as ones that contain formulas.See http://www.ruby-doc.org/stdlib/libdoc/observer/rdoc/index.html for more details on Observable