-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgettersetter.rb
More file actions
63 lines (50 loc) · 1.01 KB
/
Copy pathgettersetter.rb
File metadata and controls
63 lines (50 loc) · 1.01 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
53
54
55
56
57
58
59
60
61
62
63
=begin #Muy ssimilar a Java
class Profesor
def initialize(nombre)
@nombre = nombre
end
def get_nombre
@nombre
end
def set_nombre (nombre)
@nombre = nombre
end
end
danny = Profesor.new("Danny")
danny.set_nombre("Andres")
puts danny.get_nombre
=end
=begin #Asi seria en ruby
class Profesor
def initialize(nombre)
@nombre = nombre #propiedad
end
#geeter
def nombre #se le pone el nombre de la propiedad
@nombre
end
#setter
def nombre=(nombre)
@nombre = nombre
end
end
danny = Profesor.new("Danny")
danny.nombre= "Andres"
puts danny.nombre
=end
#Asi seria con ruby con metodos de ruby
class Profesor
#attr_accessor -Setter -getter
#attr_reader Getter
#attr_writer setter
attr_accessor :nombre, :edad
def initialize(nombre, edad)
@nombre = nombre
@edad = edad
end
end
danny = Profesor.new("Danny", 24)
danny.nombre= "Andres"
danny.edad = 20
puts danny.nombre
puts danny.edad