-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.rb
More file actions
53 lines (40 loc) · 882 Bytes
/
6.rb
File metadata and controls
53 lines (40 loc) · 882 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
class Car
attr_reader :state
attr_writer :state
# attr_accessor :state # it acts as reader and writer
def initialize engine, tires
@engine = engine
@tires = tires
p 'Car with engine ' + engine
end
def start
@state = 'running'
p 'Car Started!'
end
def stop
@state = 'stopped'
p 'Car stopped!'
end
def status #Esto lo creo para no tener que usar el attr_reader, que es como
# hacer una funcion publica en php. En un objeto mejor las variables
# privadas
p 'Car status: ' + @state
end
end
car = Car.new "1.6 Petrol", [1,2,3,4]
# puts car.inspect
car.start
p 'the car is ' + car.state
car.stop
p 'the car is ' + car.state
#attr_writer let us do : car.state = 'Stopped'
p '#################'
opel = Car.new('2.0', '4')
opel.start
p opel.state
opel.state = 'Calado'
p opel.state
opel.stop
p opel.state
opel.status
p '#################'