Ruby add dynamic events using AASM

638 views Asked by At

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.

1

There are 1 answers

0
Benoit Garret On BEST ANSWER

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