Domanda

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.

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top