Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
January 2, 2016 14:49
-
-
Save Nayshins/8319654 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) | |
@board = board | |
end | |
def create_word(*coords) | |
coords.map { |coord| @board[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
@board[row] | |
end | |
def get_col(col) | |
@board.map { |element| element[col] } | |
end | |
def get_letter(row, col) | |
@board[row][col] | |
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([1,2],[1,1],[2,1],[3,2]) #=> dock | |
print boggle_board.get_row(0) #=> b r a e | |
puts | |
puts boggle_board.get_col(1) #=> r o c a | |
puts | |
puts boggle_board.get_letter(3,2) #=> 'k' | |
# Bonus to come soon | |
# Reflection | |
# After getting used to OOP it is starting to make much more sense to me than it was in august when I first saw a class. | |
# Some benefits of using OOP is that it allows the same code to be used many time for different objects, while procedural | |
# needs to be updated for changes. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment