-
Notifications
You must be signed in to change notification settings - Fork 0
Declarative relations between object attributes.
License
nome/ruby-cells
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ruby-cells: Declarative relations between object attributes. ============================================================ ruby-cells was inspired by the Cells extension to the Common Lisp Object System (CLOS), which in turn was inspired by spreadsheet applications. See http://common-lisp.net/project/cells/ Basically, by loading the cells.rb library, you can define special attributes called cells (shamelessly ripping the standard Cells example ;-): class Motor cell :status end Like attr_accessors, this will define getter and setter methods for @status. Hower, these accessor methods differ from the standard ones in that they allow you to establish dynamic relationships between cells: class Motor cell :temperature def initialize self.temperature = 0 calculate :status do if self.temperature < 100 :on else :off end end end end That is, when creating a new Motor instance, the block associated with calculate is run and @status is assigned the value :on (since temperature was previously initialized to 0). Nothing fancy so far. However, whenever the value of temperature is changed (assuming its setter method is used), the block will be automatically re-run and @status will be updated accordingly. Also, you can register custom observers for changes to particular cells: motor = Motor.new motor.observe :status do |old, new| puts "Motor is now #{new}." end A slightly more sophisticated example is provided in motor-control.rb. For an idea of how to apply this to model/view design (in the context of Qt), see model-view.rb.
About
Declarative relations between object attributes.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published