Skip to content

Commit

Permalink
Alter the structure to allow a single object as argument for people
Browse files Browse the repository at this point in the history
  • Loading branch information
sumairq committed Apr 28, 2022
1 parent ed621cb commit 48d44db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions people.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative './teacher'

class People
attr_reader :list
attr_accessor :list

def initialize
@list = []
Expand All @@ -11,8 +11,7 @@ def initialize
def add_person(person)
new_person = person.create_person
@list << new_person
save_people_data(@list)
File.open("person.txt", "a") { |f| f.write "\n#{new_person}" }
# save_people_data(@list)
end

def filter_with_index(index)
Expand Down Expand Up @@ -48,7 +47,8 @@ def create_person
permision = input == 'Y'
end
end
Student.new(nil, @age, @name, parent_permission: permision)
Student.new({ 'classroom' => nil, 'age' => @age, 'id' => Random.rand(1..1000), 'name' => @name,
'parent_permission' => permision })
end
end

Expand All @@ -57,6 +57,6 @@ def create_person
super
puts 'Specialization:'
specialization = gets.chomp.strip.capitalize
Teacher.new(specialization, @age, @name)
Teacher.new({ 'specialization' => specialization, 'age' => @age, 'id' => Random.rand(1..1000), 'name' => @name })
end
end
14 changes: 7 additions & 7 deletions person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class Person < Nameable
attr_reader :id
attr_accessor :name, :age, :rentals
attr_accessor :name, :age, :rentals, :parent_permission

def initialize(age, name = 'unknown', parent_permission: true)
def initialize(age, id = Random.rand(1..1000), name = 'unknown', parent_permission: true)
super()
@id = Random.rand(1..1000)
@age = age
@id = id
@name = name
@parent_permission = parent_permission
@rentals = []
Expand All @@ -27,13 +27,13 @@ def to_s
"ID: #{@id} Name: #{@name} Age: #{age}"
end

def add_rentals(date, book)
Rental.new({ 'date' => date, 'person' => self, 'book' => book })
end

private

def of_age?
@age >= 18
end

def add_rentals(date, book)
Rental.new(date, self, book)
end
end

0 comments on commit 48d44db

Please sign in to comment.