Skip to content

Instantly share code, notes, and snippets.

@jgnagy
Last active August 22, 2016 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgnagy/4c4dcf94e7514adeb259e822541f3531 to your computer and use it in GitHub Desktop.
Save jgnagy/4c4dcf94e7514adeb259e822541f3531 to your computer and use it in GitHub Desktop.
tenant.rb
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Tenant
attr_reader :nickname, :occupation
attr_writer :nickname, :occupation
def initialize f_name, l_name, born_on, gender
@f_name = f_name
@l_name = l_name
@born_on = born_on
@gender = gender
end
def full_name
"#{@f_name} '#{@nickname}' #{@l_name}"
end
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
apartment.rb
class Apartment
attr_accessor :tenants
def initialize unit, num_beds, num_baths
@unit = unit
@num_beds = num_beds
@num_baths = num_baths
@tenants = []
end
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
apartment_tenants.rb
require_relative 'apartment'
require_relative 'tenant'
tenant_1 = Tenant.new "Eric", "Rowing", "April 21st, 1972", "male"
tenant_1.nickname = "E"
tenant_1.occupation = "Lawyer"
tenant_2 = Tenant.new "Jake", "Daniels", "March 3rd, 1990", "male"
tenant_2.nickname = ""
tenant_2.occupation = "Carpenter"
tenant_3 = Tenant.new "Nancy", "Lee", "December 4th, 1988", "female"
tenant_3.nickname = "Sunshine"
tenant_3.occupation = "Police Officer"
tenant_4 = Tenant.new "Isaac", "Farmer", "June 16th, 1983", "male"
tenant_4.nickname = "Baker"
tenant_4.occupation = "Entrepreneur"
puts tenant_1.full_name
puts tenant_2.full_name
puts tenant_3.full_name
puts tenant_4.full_name
apartment1 = Apartment.new(101, 3, 2)
apartment1.tenants << tenant_1
apartment1.tenants << tenant_2
# and so on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment