我在一个处理游戏状态的程序中有一个类。我实际上是用 AASM 处理它,所以要创建一个事件,我必须在aasm_event :name ...
类内部使用类似的东西。
我需要能够加载其他必须动态向类添加事件和状态的文件。
这怎么可能 ?
先感谢您。
以下应该有效,除非aasm_state
并且aasm_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