-
-
Save jrod01/2852677 to your computer and use it in GitHub Desktop.
Assignment
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 Table | |
attr_accessor :color, :seats, :material, :type, :legs | |
def initialize(inital_hash=nil) | |
initial_hash.each do |k,v| | |
instance_variable_set("@#{k}", v) | |
end if intial_hash | |
end | |
def pretty_print | |
"#{color} - #{seats} - #{material} - #{type} legs: #{how_many_legs}" | |
end | |
[:color, :seats, :material, :type, :legs].each do |attr| | |
define_method("pretty_print_#{attr}") do | |
"#{attr.to_s.capitalize}: #{instance_variable_set_get("@#{attr}")}" | |
end | |
end | |
def map_pages | |
maped_pages = pages | |
pages.each_with_index do |page, i| | |
maped_pages[i] = yield(page) | |
end | |
maped_pages | |
end | |
end | |
# Unit tests | |
require 'minitest/autorun' | |
class TestTable < MiniTest::Unit::TestCase | |
def setup | |
@table = Table.new(color: "black", seats: "4" :material "wood" :type "dining_table" :legs: "4") | |
end | |
def test_that_table_has_color | |
assert_equal "brown", @table.color | |
end | |
def test_that_table_has_seats | |
assert_equal "4", @table.seats | |
end | |
def test_that_table_has_material | |
assert_equal "wood" @table.material | |
end | |
def test_that_table_has_type | |
assert_equal "dining_table" | |
end | |
def test_that_table_has_legs | |
assert_equal "4" | |
end | |
def test_that_table_can_print_pretty | |
assert_equal "The #{@table.color} can seat #{@table.seats} ", @table.pretty_print | |
end | |
end | |
brookr
commented
Jun 1, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment