Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
January 4, 2016 21:29
-
-
Save alarson8/8681459 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle 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(dice_grid) | |
@dice_grid = dice_grid | |
end | |
def create_word(*coords) | |
coords.map { |coord| @dice_grid[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
@dice_grid[row] | |
end | |
def get_col(col) | |
@dice_grid.collect {|row| row[col] } | |
end | |
def get_diagonal#(coord) I ended up quiting the bonus. Here i tried to at least display the 0,0... 3,3 pairs; but reiceved nil, nil, nil, nil | |
@dice_grid.collect {|row, col| 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) | |
#*** DRIVER CODE *** | |
puts boggle_board.get_diagonal.inspect | |
puts boggle_board.create_word([3,2]) | |
puts boggle_board.create_word([0,1], [0,2], [1,2]) | |
puts boggle_board.get_col(0).join("") | |
puts boggle_board.get_col(1).join("") | |
puts boggle_board.get_col(2).join("") | |
puts boggle_board.get_col(3).join("") | |
puts boggle_board.get_row(0).join("") | |
puts boggle_board.get_row(1).join("") | |
puts boggle_board.get_row(2).join("") | |
puts boggle_board.get_row(3).join("") | |
#You just made a transition from procedural programming to object-oriented programming! | |
#1) How is the implementation different? | |
# We keep each method within the class, as each relates to the initialized boggle board it recieves from the class. | |
#2) What are the benefits to using the Object Oriented approach (even if it is a bit more code?) | |
# The functions of the program are seperate, yet are tied to the original class iniatilize input. | |
# We keep the code clea, and easy to read as well. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment