Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juliahimmel/8747544 to your computer and use it in GitHub Desktop.
Save juliahimmel/8747544 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
def initialize(board)
@board = board
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
def get_row(row)
@board[row].join("")
end
def get_col(col)
@board.map { |i| i[col] }.join("")
end
end
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
boggle_board = BoggleBoard.new(dice_grid)
puts boggle_board.create_word([2,1], [1,1], [1,2], [0,3]) #=> returns "code"
puts boggle_board.create_word([0,1], [0,2], [1,2]) #=> returns "rad"
puts boggle_board.create_word([3,0], [3,1], [3,2], [3,3]) #=> returns "take"
puts boggle_board.create_word([0,1], [1,1], [2,1], [3,2]) #=> returns "rock"
puts boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) #=> returns "dock"
puts boggle_board.get_row(0) #=> returns "brae"
puts boggle_board.get_row(1) #=> returns "iodt"
puts boggle_board.get_row(2) #=> returns "eclr"
puts boggle_board.get_row(3) #=> returns "take" which is a real word
puts boggle_board.get_col(0) #=> returns "biet"
puts boggle_board.get_col(1) #=> returns "roca"
puts boggle_board.get_col(2) #=> returns "adlk"
puts boggle_board.get_col(3) #=> returns "etre"
puts boggle_board.create_word([3,2]) #=> returns k
# Reflection:
# It's definitely useful to have an object with particular behaviors that can be
# used in the future. The bigger your application, the more I can see this being
# crucial. I have these methods, and they work; I don't have to worry about them
# after that. I can also base other classes in this one in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment