= volute It could be a 'set event bus', or a 'business logic relocator'. It can be used to implement toy state machines, or dumb rule systems. See examples/ and specs/ == usage gem install volute == example : equation # license is MIT $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'volute' # # our class class Equation include Volute attr_accessor :km, :h, :kph def initialize @km = 1.0 @h = 1.0 @kph = 1.0 end def inspect "#{@km} km, #{@h} h, #{@kph} kph" end end # # a volute triggered for any 'set' operation on an attribute of book volute Equation do # object.vset(:state, x) # is equivalent to # object.instance_variable_set(:@state, x) volute :km do object.vset(:h, value / object.kph) end volute :h do object.vset(:kph, object.km / value) end volute :kph do object.vset(:h, object.km / value) end end # # trying e = Equation.new p e # => 1.0 km, 1.0 h, 1.0 kph e.kph = 10.0 p e # => 1.0 km, 0.1 h, 10.0 kph e.km = 5.0 p e # => 5.0 km, 0.5 h, 10.0 kph == example : some kind of state-machine # license is MIT # # a state-machine-ish example, inspired by the example at # http://github.com/qoobaa/transitions $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'volute' # # our class class Book include Volute attr_accessor :stock attr_accessor :discontinued attr_reader :state def initialize (stock) @stock = stock @discontinued = false @state = :in_stock end end # # a volute triggered for any 'set' operation on an attribute of book volute Book do # object.volute_do_set(:state, x) # is equivalent to # object.instance_variable_set(:@state, x) if object.stock <= 0 object.volute_do_set( :state, object.discontinued ? :discontinued : :out_of_stock) else object.volute_do_set( :state, :in_stock) end end # # trying emma = Book.new(10) emma.stock = 2 p emma.state # => :in_stock emma.stock = 0 p emma.state # => :out_of_stock emma.discontinued = true p emma.state # => :discontinued == license MIT, see LICENSE.txt