title: How to get the first key and value pair from a hash table in Ruby
body: <p>I'm trying to get the first key and value key from a hash table in ruby. I don't know the key values of the hash because it is passed to the method. I cant find anywhere online how to find the first key/value as a separate hash table. 
  I think <code>hash[0]</code> will just try to find an element with a name 0 it just returns <code>nil</code> when I run the code. </p>
  
  <p>I know I can find the key name and the value and then create a new hash from them but i wonder if there is an easier way to do this so I get a hash right away. </p>
  
  <p>here is my code: </p>
  
  <pre><code>def rps_game_winner(game)
  
  rock_in_hash = game.invert['R']
  paper_in_hash = game.invert['P']
  scissors_in_hash = game.invert['S']
  
  if(rock_in_hash)
        if(paper_in_hash)
          return paper_in_hash;
        elsif(scissors_in_hash)
          return rock_in_hash
        end
      elsif(paper_in_hash)
        if(rock_in_hash)
          return paper_in_hash
        elsif(scissors_in_hash)
          return scissors_in_hash
        end
      end
          key = game.keys[-1]
          value = game.values[-1]
              winner = {key =&gt; value}
      return winner 
      end
  
  game_one = { "Bob" =&gt; 'P', "Jim" =&gt; 'P' }
  
  puts rps_game_winner(game_one)
  </code></pre>
  
  <p>This gets me the correct result the problem is I don't understand why it's -1 instead of zero...
  And i was hoping there was a better way to get the first key/value pair of a hash table instead of creating new hash table with the key and value you retrieved from the previous table. </p>