-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.rb
45 lines (36 loc) · 812 Bytes
/
person.rb
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
# person.rb
require_relative 'nameable'
#
# Class representing a person in the library application
#
class Person < Nameable
attr_accessor :name, :age, :id
attr_reader :rentals
def initialize(name = 'Unknown', age = 0, parent_permission: true)
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
# Instead of setter for entire collection a method to add one by one
def rental=(rental)
@rentals << rental
rental.person = self
end
# Method to add a rental for this person
def add_rental(date, book)
Rental.new(date, book, self)
end
private
def of_age?
@age.to_i >= 18
end
end