From: Ronggen Pan Date: 2005-12-26T09:02:36+09:00 Subject: Ruby Eventing ------=_NextPart_000_000C_01C6097D.5A1D27E0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, While working on a state machine work flow, I need a flexible way to define event/event handling. Since I came from C# background, so I have come up event.rb to share with everyone. Welcome for comments. Here's the example codes. You can get event.rb from http://competo.com/code/event.rb. Thanks! class CoffeeMaker include Event def initialize event 'brew_ready' event 'brewing_started' end def brew on_brewing_started('new brew started') #brewing ... on_brew_ready('coffee is ready!') end end class CoffeeLover def get_coffee(*args) puts "thanks for the coffee!" end end cm = CoffeeMaker.new cm.brewing_started('+s1') {|*args| puts args} cm.brew_ready('+s2') {|*args| puts args} cl = CoffeeLover.new cm.brew_ready('+s3') {|*args| cl.get_coffee args} # add sink with + cm.brew cm.brew_ready('-s3') #remove sink with - cm.brew produces ... new brew started thanks for the coffee! coffee is ready! new brew started coffee is ready! ------=_NextPart_000_000C_01C6097D.5A1D27E0--