From: Pit Capitain Date: 2005-05-26T17:57:50+09:00 Subject: Re: Invoking a Class block on an Instance Gavin Kistner schrieb: > ... > Unfortunately, I can't figure out how to get an instance of a class to > invoke a block stored in its parent class, using the scope of the > instance for the block. In JS this would be easy, but I don't yet grok > how to have Ruby run a set of code on any arbitrary scope (while > passing parameters to that code). Hi Gavin, executing a code block in the context of an object is normally done via instance_eval, but I, too, couldn't find a way to pass parameters to the block. One workaround is to create methods for the states. If you change the following methods of FiniteStateMachine, it should work: class FiniteStateMachine ... def self.add_state( start_state, &block ) name = "__state_#{start_state}" states[ start_state ] = name define_method( name, &block ) end ... def transition( trigger ) @state = send( self.class.states[ @state ], trigger ) end end Regards, Pit