-
-
Save Osagiede/91c35be9580ed5df2937f91c74d8f416 to your computer and use it in GitHub Desktop.
How to import objects created from a class from one file to another?
This file contains 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
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 | |
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 | |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
apartment.rb | |
class Apartment | |
def initialize unit, num_beds, num_baths | |
@unit = unit | |
@num_beds = num_beds | |
@num_baths = num_baths | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment