-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.rb
More file actions
73 lines (60 loc) · 1.34 KB
/
person.rb
File metadata and controls
73 lines (60 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require_relative 'nameable'
require_relative 'decorator'
class Person < Nameable
attr_accessor :name, :age, :parent_permission, :rentals
attr_reader :id
def initialize(age, name = 'Unknown', parent_permission = true)
super()
@id = Random.rand(1..1000)
@name = name
@age = age
@parent_permission = parent_permission
@rentals = []
end
def can_use_services?
of_age? || parent_permission
end
def correct_name
name
end
def self.all
ObjectSpace.each_object(self).to_a
end
def to_s
index = Person.all.index(self)
"#{index})"
end
def of_age?
age >= 18
end
def self.list_people
puts 'List of people:'
all_people = all.empty? ? 'No people available yet' : all
puts all_people
all_people
end
def self.create_person
puts
puts 'Do you want to create a student (1) or a Teacher (2)? [Input the number]'
option = gets.chomp
case option
when '1'
Student.create_student
when '2'
Teacher.create_teacher
else
puts
puts 'That is not a valid input'
end
end
def self.select_person_to_rent
puts 'Select a person from the following list by number (not id)'
puts all
person = gets.chomp.to_i
if person > all.length || person.negative?
puts 'Invalid person number'
return
end
person
end
end