Skip to content

Instantly share code, notes, and snippets.

@luikore
Created June 24, 2009 10:53
Show Gist options
  • Save luikore/135159 to your computer and use it in GitHub Desktop.
Save luikore/135159 to your computer and use it in GitHub Desktop.
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