title: Working with instance variables within a model
body: <p>I want to instantiate a "Battle" upon creation with some variables that I can manipulate without accessing the database and then first when all the method calls and calculation has been done, save the battle result to the database. I want the "player" method to return the sorted array that was created in the callback, but at the moment it just returns nil</p>
  
  <pre><code>class Battle &lt; ActiveRecord::Base
      after_create do
        @battlelog = ""
        @field = []
        @conditions = []
        @player = sort_by_initiative(action.character.army.members.map{ |m| [m.unit, m.amount]})      
          @computer = sort_by_initiative(action.instance.members.map{ |m| [m.unit, m.amount]})
      end
  
      # Associations
      belongs_to :action
  
      def sort_by_initiative(array)
          array.sort { |a, b| b.first.initiative &lt;=&gt; a.first.initiative }
      end
  
      def player
          @player
      end
  </code></pre>