Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
December 27, 2015 17:49
-
-
Save leishman/7365249 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle class challenge
This file contains 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
## NOTE: THERE IS AN ERROR AND THE SAME GIST IS BEING USED FOR BOGGLE AND PEZ. NOT SURE WHY. HERE IS MY PEZ CLASS: | |
class Pez | |
def initialize(pez) | |
@pez = pez | |
end | |
def get_pez | |
@pez.pop | |
end | |
def pez_count | |
@pez.size | |
end | |
def add_pez(new_pez) | |
@pez + new_pez.to_a | |
end | |
def see_all_pez | |
@pez | |
end | |
end | |
flavs = %w{apple pear sugar water purple} | |
mario = Pez.new(flavs) | |
newp = mario.get_pez | |
p newp | |
p mario.pez_count | |
##### HERE IS MY BOGGLE CLASS | |
# Solution for Challenge: A Nested Array to Model a Boggle Board. Started 2013-11-04T03:21:24+00:00 | |
class BoggleBoard | |
attr_reader :board | |
def initialize(board) | |
@board = board | |
end | |
def get_row(x) | |
@board[x] | |
end | |
def get_col(x) | |
col = [] | |
1.upto(@board.length) { |i| col << @board[i-1][x] } | |
return col | |
end | |
end | |
dice_board = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
b = BoggleBoard.new(dice_board) | |
# implement tests for each of the methods here: | |
p b.board[1][1] == "o" | |
p b.get_col(0) == ["b", "i", "e", "t"] | |
p b.get_row(3) == ["t", "a", "k", "e"] | |
# create driver test code to retrieve a value at a coordinate here: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment