Created
June 24, 2009 10:53
-
-
Save luikore/135159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'state_machine' | |
class StateMachine::Machine | |
def par_event events, test_field, trans | |
i = 1 | |
# binary 11....1 | |
full = (1 << events.size) - 1 | |
events.each do |e| | |
j = i | |
event e do | |
transition(hash.merge(:if => (lambda{ |obj| | |
# if all events are fired | |
# then test_field == full | |
# then transition will be done | |
new_tf = ((obj.send(test_field) || 0) | j) # new test field | |
obj.send "#{test_field}=", new_tf | |
full == new_tf | |
}))) | |
end | |
i = i << 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment