-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathperson.rb
More file actions
46 lines (38 loc) · 786 Bytes
/
person.rb
File metadata and controls
46 lines (38 loc) · 786 Bytes
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
require_relative 'nameable'
require_relative 'rental'
class Person < Nameable
attr_reader :id
attr_accessor :name, :age, :rentals
def initialize(parent_permission: true, name: 'Unknown', age: nil)
super()
@id = Random.rand(1..1000)
@name = name
@age = age
@parent_permission = parent_permission
@rentals = []
end
def correct_name
@name
end
def can_use_services?
of_age? || @parent_permission
end
def add_rental(date, book)
rental = Rental.new(date, book, self)
@rentals << rental
book.add_rental(rental)
rental
end
def to_hash
{
type: self.class.name,
age: @age,
name: @name,
parent_permission: @parent_permission
}
end
private
def of_age?
@age.to_i >= 18
end
end