2011-10-08 79 views
1

我有一個正在處理遊戲狀態的程序。我實際上是用AASM來處理它,所以要創建一個活動,我必須在課堂中使用類似aasm_event :name ...的東西。Ruby使用AASM添加動態事件

我需要能夠加載其他動態必須添加事件和狀態的類的文件。

這怎麼可能?

預先感謝您。

回答

1

以下應該工作,除非aasm_stateaasm_event保護或私有:

# game.rb 
class Game 
    include AASM 

    aasm_initial_state :start 
end 

# add the require after the class definition, else it will complain of a missing constant 
require "other_file" 

# other_file.rb 
Game.aasm_state :another_state 
Game.aasm_event do 
    transitions :to => :another_state, :from => [:start] 
end 
+0

謝謝:)這應該工作! – Cydonia7