Skip to content

Instantly share code, notes, and snippets.

@collinschaafsma
Created November 14, 2012 22:53
Show Gist options
  • Save collinschaafsma/4075427 to your computer and use it in GitHub Desktop.
Save collinschaafsma/4075427 to your computer and use it in GitHub Desktop.
class Hood
attr_accessor :houses
def initialize(houses)
@houses = houses
end
def house_count
@houses.count
end
def total_bedrooms
bedroom_count = 0
@houses.each do |house|
bedroom_count = bedroom_count + house.bedrooms
end
bedroom_count
end
def address
"123 Common St."
end
end
class House
def initialize(bedrooms)
@bedrooms = bedrooms
end
def price
200000 * @bedrooms
end
def window
@bedrooms
end
def bedrooms
@bedrooms
end
def bedrooms=(bedrooms)
@bedrooms = bedrooms
end
end
# my_house = House.new(2)
# puts my_house.price
# my_big_house = House.new(6)
# puts my_big_house.price
# puts my_big_house.bedrooms
# my_big_house.bedrooms = 15
# puts my_big_house.bedrooms
# puts my_big_house.price
house_one = House.new(1)
house_two = House.new(2)
house_three = House.new(6)
houses = [house_one, house_two, house_three]
hood = Hood.new(houses)
puts hood.house_count
puts hood.houses[1].price
puts hood.total_bedrooms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment