Inheritance with state_machine
Categories: ruby, state_machine
Below is a simple example of inheritance that seems to work for me with state_machine. There could be a better way to do it but I wasn't able to find it. In this example, the initial state is inherited from the base class.
class Procedure
state_machine :initial => :not_started do
#More Procedure-specific events and whatnot
end
end
class BusinessProcedure < Procedure
state_machine do
after_transition :on => :start_work do |obj|
obj.inflate_billable_hours
end
end
end
Stay DRY folks! By the way, I am aware of the weird indentation going on in my code samples (and the lack of code highlighting). The lack of code highlighting is because I haven't implemented it yet. The weird indentation is because Markdown is not performing as it should. I will fix it eventually.
Comments