forked from simonhoyos/oop-ruby-example1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.rb
More file actions
68 lines (58 loc) · 971 Bytes
/
example1.rb
File metadata and controls
68 lines (58 loc) · 971 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Person
# attr_reader :name, :age
# attr_writer :age
attr_accessor :name, :age
def initialize(name, age, weight, email)
@name = name
@age = age
@weight = weight
puts self.greet("mundo")
end
def greet(other_person)
random_number = self.random_number
"Hola #{other_person}! me llamo #{@name}"
end
def grow
@age += 1
end
def is_dead?
if @age >= 100
true
else
false
end
end
def getFat
@weight += 10
end
def do_exercise
@weight -= 5
end
# Creamos la función getter para name
# def name
# @name
# end
# Creamos la función setter para name
# def name=(name)
# @name = name
# end
def random_number
rand(1..10)
end
end
p1 = Person.new("Simon", 25)
puts p1.greet("clase")
puts p1.name
puts p1.age
# p1.age = 26
p1.grow
puts p1.age
p1.name = "Juan"
puts p1.name
puts p1.class
puts p1.isDead?
100.times do
p1.grow
end
puts p1.age
puts p1.isDead?