title: What strategy do I use to avoid global variables in ruby?
body: <p>I'm learning Ruby through 'Learn to Program' by Chris Pine. I'm trying to cope without global variables. I have a sloppy looking command prompt blackjack program (can't split yet) My first three methods illustrate the problem I'm having. In Pascal I would have used global variables, and used methods to manipulate those global variables. It would look something like this (using ruby pseudo language)</p>
  
  <pre><code>$deck_of_cards = []
  $player_hand   = []
  $dealer_hand   = []
  
  def create_deck
      $deck_of_cards = #numbers 1-52
  end
  
  def shuffle_deck
      $deck_of_cards = #shuffled up deck of cards
  end
  
  def opening_deal
      2.times do
          $player_hand.push $deck_of_cards.pop
          $dealer_hand.push $deck_of_cards.pop
      end
  end
  
  create_deck
  shuffle_deck
  opening_deal
  </code></pre>
  
  <p>and I would end up with a shuffled deck, a player hand, and a dealer hand.  </p>
  
  <p>Taking away global variables, the first two methods now look like this:</p>
  
  <pre><code>def create_deck deck_of_cards
      deck_of_cards = #numbers 1-52
      return deck_of_cards
  end
  
  def shuffle_deck deck_of_cards
      deck_of_cards = #shuffled up deck of cards
      return deck_of_cards
  end
  
  deck = create_deck([])
  deck = shuffle_deck(deck)
  </code></pre>
  
  <p>which feels a little odd but I could get used to it.  </p>
  
  <p>But I'm completely stuck on the last method, which would need to return two variables, player_hand and dealer_hand.  I could push those two arrays into another array and return that, but that doesn't seem like it's simplifying anything.  </p>
  
  <p>Is there a general strategy for dealing with this, or does each situation have its own unique solution?</p>
  
  <p>Another situation that comes to mind is a chess program.  Why would it not make sense to make the chess board a global variable since almost all methods in a chess program would need to use it's value?</p>