I am creating a card game with several classes. I currently use global variables to store $shuffled_deck , $players_hand and $dealers_hand , but I am worried about using global variables (perhaps unnecessarily) and prefer to use instance variables.
I read, but clicks nothing. Can anyone help point me in the right direction?
Using Instance Variables I was unable to save @players_hand and @dealers_hand to use in other classes. For example, I have @players_hand from the Player class. I have the Dealer class draw a map, but I can not pull this @players_hand into the Dealer class to add them together.
My current code is:
 class Blackjack def initialize @player = Player.new @dealer = Dealer.new end end class Dealer def initialize @deck = Deck.new $dealers_hand = 0 end def hit_dealer @deck.hit_dealer end def hit_player @deck.hit_player end def draw_card @hit = $shuffled_deck end def shuffle @deck.suits end end class Player def initialize $players_hand = 0 end end class Deck def suits  
Alekx  source share