From: "Jesús Gabriel y Galán" Date: 2011-09-30T03:47:44+09:00 Subject: Re: Variables, Arrays and Hashes. On Thu, Sep 29, 2011 at 8:40 PM, Rob V. wrote: > I'm trying to make a card game with Ruby. I created a hash of cards and > numeric values which works fine on its own: > example: >     deck = Hash.new >     deck["Ah"] = 1 >     deck["1h"] = 1 >     deck["2h"] = 2 >     deck["3h"] = 3 >     deck["4h"] = 4 >     deck["5h"] = 5 > where: >     puts deck["3h"] > properly returns 3. > > I wrote some code to output the hash into an array and then shuffle it > which also works. I have code to deal out the cards into new arrays for > each player which works as well. My issue is when I try to call things > like: > >     puts player1.first > it will give the appropriate first card in the hand but: > >     puts deck[player1.first] > does not return the value of the card. I've also tried created place > holder variables without avail: > >     x = player1.first >     puts x > gives the proper output of the card in hand but: > >     puts deck[x] > comes up a blank line. > Any thoughts? Can you show a complete example in which we can see the error? Things to check: - Are you sure you are putting the keys of the hash in the arrays? - What does puts player1.first outputs: "Ah" or 1? Jesus. Jesus.