Sha256: 9512bededcd42cbeb8fbffc8b8a2674bf43a44da227ea00b1d054eb37b206d74

Contents?: true

Size: 953 Bytes

Versions: 16

Compression:

Stored size: 953 Bytes

Contents

require 'rubygems'
require 'stateflow'

class Test
  include Stateflow
  
  stateflow do
    
    initial :love
    
    state :love do
      enter lambda { |t| p "Entering love" }
      exit :exit_love
    end
    
    state :hate do
      enter lambda { |t| p "Entering hate" }
      exit lambda { |t| p "Exiting hate" }
    end
    
    state :mixed do
      enter lambda { |t| p "Entering mixed" }
      exit lambda { |t| p "Exiting mixed" }
    end
    
    event :b do
      transitions :from => :love, :to => :hate, :if => :no_ice_cream
      transitions :from => :hate, :to => :love
    end
    
    event :a do
      transitions :from => :love, :to => [:hate, :mixed], :decide => :likes_ice_cream?
      transitions :from => [:hate, :mixed], :to => :love
    end
  end
  
  def likes_ice_cream?
    rand(10) > 5 ? :mixeds : :hate
  end
  
  def exit_love
    p "Exiting love"
  end
  
  def no_ice_cream
    rand(4) > 2 ? true : false
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
multiflow-1.0.0 examples/test.rb
stateflow-0.5.0.beta examples/test.rb
stateflow-0.4.2 examples/test.rb
stateflow-0.4.1 examples/test.rb
stateflow-0.4.0 examples/test.rb
stateflow-0.3.0 examples/test.rb
stateflow-0.2.3 examples/test.rb
stateflow-0.2.2 examples/test.rb
stateflow-0.2.1 examples/test.rb
stateflow-0.2.0 examples/test.rb
stateflow-0.1.2 examples/test.rb
stateflow-0.1.1 examples/test.rb
stateflow-0.1.0 examples/test.rb
stateflow-0.0.4 examples/test.rb
stateflow-0.0.3 examples/test.rb
stateflow-0.0.2 examples/test.rb