2011-10-08 2 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