-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.rb
More file actions
43 lines (35 loc) · 771 Bytes
/
Copy pathperson.rb
File metadata and controls
43 lines (35 loc) · 771 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
require './nameable'
class Person < Nameable
attr_reader :id, :rentals
attr_accessor :name, :age
def initialize(age:, id: nil, name: 'Unknown', parent_permission: true)
super()
@id = id.nil? ? Random.rand(1..1000) : id
@name = name
@age = age
@parent_permission = parent_permission
@rentals = []
end
def to_json(_args)
JSON.dump({
id: @id,
name: @name,
age: @age,
parent_permission: @parent_permission,
rentals: @rentals
})
end
def add_rental(rental)
@rentals << rental
end
def can_use_service?
of_age? || @parent_permission
end
def correct_name
@name
end
private
def of_age?
@age >= 18
end
end