I've got a class in a program which is handling game states. I'm actually handling it with AASM so to create an event I have to use something like aasm_event :name ...
inside the class.
I need to be able to load other files who dynamically have to add events and states to the class.
How is it possible ?
Thank you in advance开发者_JAVA百科.
The following should work, unless aasm_state
and aasm_event
are protected or private:
# 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
精彩评论