Skip to content

Instantly share code, notes, and snippets.

@hassox
Created April 6, 2010 12:49
Show Gist options
  • Save hassox/08453296ebd63a3bd8dd to your computer and use it in GitHub Desktop.
Save hassox/08453296ebd63a3bd8dd to your computer and use it in GitHub Desktop.
# Defines an initialization hook into the owner class for setting the
# initial state of the machine *before* any attributes are set on the
# object
def define_state_initializer
@instance_helper_module.class_eval <<-end_eval, __FILE__, __LINE__
def initialize(attributes = {}, *args)
ignore = attributes ? attributes.keys : []
initialize_state_machines(:dynamic => false, :ignore => ignore)
super
initialize_state_machines(:dynamic => true, :ignore => ignore)
end
end_eval
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment