Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
January 3, 2016 01:39
-
-
Save manubete/8390845 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle class challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoggleBoard | |
def initialize(board) | |
@boggle_board = board | |
@diag = [] | |
end | |
def create_word(*coords) | |
coords.map { |coord| @boggle_board[coord.first][coord.last] }.join("") | |
end | |
def get_row(row_number) | |
@boggle_board[row_number] | |
end | |
def get_col(col) | |
@boggle_board.transpose[col] | |
end | |
def print_rows_columns | |
@boggle_board.each_with_index do |dummy, index| # index = 0 | |
p self.get_row(index).join('') # p boggleboard.get_row(3) as a string | |
p self.get_col(index).join('') # p boggleboard.get_col(3) as a string | |
end | |
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) | |
# implement tests for each of the methods here: | |
boggle_board.print_rows_columns | |
# create driver test code to retrieve a value at a coordinate here: | |
boggle_board.create_word([3,2]) | |
# Reflect | |
# An object oriented approach allowed me and David Willbanks to really encapsulate and take advantage of a single responsibility | |
# design, even for our test code. In our case we really tried to refactor as much as possible so our code ended up being quite concise. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment