title: Why do I get a syntax error with "Sinatra: Up and Running" game.rb "Rock Paper Scissors"?
body: <p>I'm following this example from "Sinatra: Up and Running", and I get the following error message:</p>
  
  <blockquote>
    <p>game.rb:8: odd number list for Hash<br />
    &nbsp;&nbsp;&nbsp;&nbsp;@defeat = { rock:&nbsp;&nbsp;:scissors, paper:&nbsp;&nbsp;:rock, scissors: &nbsp;:paper }<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^<br />
    game.rb:8: syntax error, unexpected ':', expecting '}'<br />
    &nbsp;&nbsp;&nbsp;&nbsp;@defeat = { rock: &nbsp;:scissors, paper: &nbsp;:rock, scissors: &nbsp;:paper }<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^</p>
  </blockquote>
  
  <p>after running:</p>
  
  <pre><code>$ ruby -rubygems game.rb
  </code></pre>
  
  <p>However, I have no idea why it has trouble with this statement. I copied the code straight from the book. I've tried many variations and nothing seems to work. This code is suppose to output "Ouch rock beats scissors. Better luck next time!" if I go to localhost:4567/throw/scissors and the computer chooses rock.</p>
  
  <p>game.rb below</p>
  
  <pre><code>require 'sinatra'
  
  # before we process a route, we'll set the response as
  # plain text and set up an array of viable moves that
  # a player (and the computer) can perform
  before do
    content_type :txt
    @defeat = {rock: :scissors, paper: :rock, scissors: :paper}
    @throws = @defeat.keys
  end
  
  get '/throw/:type' do
    # the params[] hash stores querystring and form data.
    player_throw = params[:type].to_sym
  
    # in the case of a player providing a throw that is not valid,
    # we halt with a status code of 403 (Forbidden) and let them
    # know they need to make a valid throw to play.
    if !@throws.include?(player_throw)
      halt 403, "You must throw one of the following: #{@throws}"
    end
  
    # now we can select a random throw for the computer
    computer_throw = @throws.sample
  
    # compare the player and computer throws to determine a winner
    if player_throw == computer_throw
      "You tied with the computer. Try again!"
    elsif computer_throw == @defeat[player_throw]
      "Nicely done; #{player_throw} beats #{computer_throw}!"
    else
      "Ouch; #{computer_throw} beats #{player_throw}. Better luck next time!"
    end
  end
  </code></pre>
  
  <p>By the way the code I used for the original question was actually one of the "fixes" I tried not the actual book code. Apparently the book code had the same thing sczizzo suggested. However, I'm still getting an error (see above). Anyway if I try sczizzo alternative:<br />
  <br /></p>
  
  <blockquote>
    <p>{ &nbsp;:rock &nbsp;=> :scissors, :paper => :rock, :scissors => :paper &nbsp;}</p>
  </blockquote>
  
  <p>then game.rb compiles, but I get a runtime error:<br /></p>
  
  <blockquote>
    <p>#&lt;NoMethodError: undefined method `sample' for [:rock, :scissors, :paper]:Array></p>
  </blockquote>
  
  <p>if I visit <a href="http://localhost:4567/throw/scissors" rel="nofollow">http://localhost:4567/throw/scissors</a></p>
  
  <p><b>Solution: Instal Ruby 1.9!</b><br />
  <b>Thanks everyone</b><br /></p>