Skip to content

Instantly share code, notes, and snippets.

@nextacademy-private
Created August 31, 2014 09:09
Show Gist options
  • Save nextacademy-private/5da07342590e72472886 to your computer and use it in GitHub Desktop.
Save nextacademy-private/5da07342590e72472886 to your computer and use it in GitHub Desktop.
class House
attr_reader :square_feet, :num_bedrooms, :num_baths, :cost
def initialize(address, square_feet, num_bedrooms = 3, num_baths = 2, cost = 320_000, down_payment = 0.20, sold = false, has_tenants = false)
@address = address
@square_feet = square_feet
@num_bedrooms = num_bedrooms
@num_baths = num_baths
@cost = cost
@down_payment = down_payment
@sold = sold
@short_sale = short_sale
@has_tenants = has_tenants
end
def obscure_address
@address.sub(/\A\d*/, '****')
end
def buy!(money, good_credit)
@sold = true if money >= down_payment && good_credit
end
def down_payment
cost * @down_payment
end
def to_s
"#{obscure_address} : #{square_feet} sq. ft., #{num_bedrooms} bed, #{num_baths} bath. $#{cost}"
end
end
@tinglesam
Copy link

class House
attr_reader :square_feet, :num_bedrooms, :num_baths, :cost

def initialize(info = {})
#address, square_feet, num_bedrooms = 3, num_baths = 2, cost = 320_000, down_payment = 0.20, sold = false, has_tenants = false)
@address = info[:address]
@square_feet = info[:square_feet]
@num_bedrooms = 3 #info[:num_bedrooms]
@num_baths = 2 #info[:num_baths]
@cost = 320_000 #info[:cost]
@down_payment = 0.2 #info[:down_payment]
@Sold = false #info[:sold]
@short_sale = info[:short_sale]
@has_tenants = false # info[:has_tenants]
end

def obscure_address
@address.sub(/\A\d_/, '_***')
end

def buy!(money, good_credit)
@Sold = true if money >= down_payment && good_credit
end

def down_payment
cost * @down_payment
end

def to_s
"#{obscure_address} : #{square_feet} sq. ft., #{num_bedrooms} bed, #{num_baths} bath. $#{cost}"
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment