Skip to content

Instantly share code, notes, and snippets.

@oddlyfunctional
Created July 7, 2017 00:01
Show Gist options
  • Save oddlyfunctional/ca4b63da39448ebb2473f3ba65b96c5c to your computer and use it in GitHub Desktop.
Save oddlyfunctional/ca4b63da39448ebb2473f3ba65b96c5c to your computer and use it in GitHub Desktop.
class Building
attr_reader :address
def initialize(rooms, address, width, length)
@rooms = rooms
@address = address
@width = width
@length = length
end
def area
@width * @length
end
def Building.price_per_square_meter(city)
case city
when "São Paulo" then 8000
when "São Cateano" then 5000
else puts "Não conheço essa cidade"
end
end
end
class Butler
attr_reader :castle
def initialize(name, castle)
@name = name
@castle = castle
end
def salary
10 * castle.area
end
end
require_relative "building"
require_relative "butler"
require 'pry'
class Castle < Building
attr_reader :butler
def initialize(rooms, address, width, length, butler = nil)
@butler = Butler.new(butler, self) if butler
super(rooms, address, width, length)
end
def has_a_butler?
@butler != nil
end
def area
super + 300 # + jardim
end
def self.categories
['Medieval', 'Norman', 'Ancient', 'Fantasy']
end
end
require_relative "building"
class House < Building
end
require_relative "house"
require_relative "castle"
ebac = House.new(50, "Mourato Coelho 1404", 14, 36)
itaipava = Castle.new(200, "Castelo de Itaipava", 100, 100, "Jenkins")
itaipava.area
p itaipava
if itaipava.has_a_butler?
puts "Itaipava tem um mordomo!"
else
puts "Itaipava não tem um mordomo..."
end
greyskull = Castle.new(500, "Castelo de Greyskull", 500, 500)
if greyskull.has_a_butler?
puts "Greyskull tem um mordomo!"
else
puts "Greyskull não tem um mordomo..."
end
[itaipava, greyskull].each do |building|
puts "#{building.address} - #{building.area}m²"
end
puts Castle.categories
puts greyskull.class.categories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment