-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.rb
45 lines (39 loc) · 862 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
require './decorator'
require './capitalizedecorator'
require './trimmerdecorator'
class Person < Nameable
# creates a getter method for @id
attr_reader :rentals
# creates getter and setter methods for @name and @age
attr_accessor :name, :age, :id
def initialize(age, name = 'Unknown', parent_permission: true)
@id = Random.rand(1..1000)
@name = name
@age = age
@parent_permission = parent_permission
@rentals = []
super()
end
def to_hash
{
id: @id,
name: @name,
age: @age,
parent_permission: @parent_permission,
rentals: @rentals.map(&:to_hash),
class: self.class.name
}
end
def can_use_services?
of_age? || @parent_permission
end
def of_age?
@age >= 18
end
def correct_name
@name
end
def add_rentals(person)
@rentals.push(person)
end
end