ruby > thoughts.find_all(&:sfw?).to_blog
 => #<URI::HTTP:0x00001 URL: http://MichaelXavier.net >
ruby > MichaelXavier.info
 =>  [ GitHub , Resume , Email ]
ruby > _

Inheritance with state_machine
01|14|2010 — 0 comments  

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 Comments RSS Feed

Add Comment

(required)
(required, won't be displayed)

(Use Markdown syntax)