-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperson.rb
executable file
·45 lines (35 loc) · 946 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_relative './decorateor'
class Person < Nameable
attr_reader :id
attr_accessor :name, :age, :rentals, :parent_permission
def initialize(age, name = 'Unknown', parent_permission: true, id: Random.rand(1..1000))
super()
@id = id
@name = name
@age = age
@parent_permission = parent_permission
@rentals = []
end
def correct_name
@name
end
def add_rental(book, _date)
@rentals.push(book)
book.rentals = self
end
def of_age?
return true if @age.to_i >= 18
false
end
private :of_age?
def can_use_services?
return true if @parent_permission == true || of_age?
false
end
end
# person1 = Person.new(22, 'maximilianus')
# puts person1.correct_name
# capitalized_person = CapitalizeDecorator.new(person1)
# puts capitalized_person.correct_name
# capitalized_trimmed_person = TrimmerDecorator.new(capitalized_person)
# puts capitalized_trimmed_person.correct_name