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
SumNodeisn't recalculated every time it is requested - instead it is updated when one of its value nodes is updated. This works recursively, so that innerSumNodesalso trigger updates. As the notification includes the uniqueidof the node, it is possible to write more complexNodetypes, such as ones that contain formulas.See http://www.ruby-doc.org/stdlib/libdoc/observer/rdoc/index.html for more details on Observable