Skip to content

Instantly share code, notes, and snippets.

@papajo
Created May 28, 2016 03:46
Show Gist options
  • Save papajo/4ac53fb33400cae7217f7635dacaa6f0 to your computer and use it in GitHub Desktop.
Save papajo/4ac53fb33400cae7217f7635dacaa6f0 to your computer and use it in GitHub Desktop.
ttt-5-move-rb-q-000  
Output:
Failures:                                                                       
                                                                                
1) ./bin/move executing a CLI Application defines a board variable            
     Failure/Error: board = get_variable_from_file("./bin/move", "board")       
     NoMethodError:                                                             
       undefined method `[]' for nil:NilClass   
2) ./bin/move executing a CLI Application calls move passing the index        
     Failure/Error: run_file("./bin/move")                                      
     NoMethodError:                                                             
       undefined method `[]' for nil:NilClass  
                                                      
Finished in 0.02334 seconds (files took 0.10083 seconds to load)                
20 examples, 2 failures                                                         
                                                                                
Failed examples:                                                                
                                                                                
rspec ./spec/03_cli_spec.rb:4 # ./bin/move executing a CLI Application defines a
 board variable                                                                 
rspec ./spec/03_cli_spec.rb:41 # ./bin/move executing a CLI Application calls mo
ve passing the index   
=============================================
Code:
/bin/move:
#!/usr/bin/env ruby
require_relative '../lib/move.rb'
# Code your CLI Here
puts "Welcome to Tic Tac Toe!"
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
display_board(board)
puts "Where would you like to go?"
input = gets.strip
index = input_to_index(input)
new_board = move(board, index, "X")
display_board(new_board)
/lib/move.rb:
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
# code your input_to_index and move method here!
def input_to_index(input)
index = input.to_i - 1
end
def move(board, index, token="X")
board[index] = token
board
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment