-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathestilo.rb
More file actions
52 lines (44 loc) · 1.02 KB
/
estilo.rb
File metadata and controls
52 lines (44 loc) · 1.02 KB
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
47
48
49
50
51
52
class PERSON
LIFE_stage = {childhood:12,teenager:19,adult:50}
LEGAL_AGE = 18
attr_reader :name
attr_writer :name
def initialize (name, age)
@name = name
@age = age
end
def age
@age
end
def life_stage
if @age < LIFE_stage[:childhood]
:childhood
elsif @age < LIFE_stage[:teenager]
:teenager
elsif @age < LIFE_stage[:adult]
:adult
else
:elder
end
end
def legal
@age >= LEGAL_AGE
end
end
# Esta parte del código son pruebas.
# Antes y después deben de imprimir puros "true"
fernando = PERSON.new("Fernando",5)
juan = PERSON.new("Juan",45)
laura = PERSON.new("Laura",87)
andrea = PERSON.new("Andrea",13)
puts fernando.legal == false
puts juan.legal == true
puts laura.legal == true
puts andrea.legal == false
puts fernando.life_stage == :childhood
puts juan.life_stage == :adult
puts laura.life_stage == :elder
puts andrea.life_stage == :teenager
puts laura.age == 87
laura.name = "Ximena"
puts laura.name == "Ximena"