-
Notifications
You must be signed in to change notification settings - Fork 2
/
class.rb
70 lines (49 loc) · 963 Bytes
/
class.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Vehicle
attr_accessor :color, :size
@@num = 0
def initialize (color = "black", size = 100)
@color = color
@size = size
@@num += 1
end
def is_black?
@color == "black"
end
def self.num
@@num
end
def method_missing(m, *args, &block)
"Sorry, \"#{m}\" are no present"
end
end
class Car < Vehicle
def initialize (color = "black", size = 100, doors = 5)
super color, size
doors = doors
end
def is_black?
@color == "grey" or super
end
end
# --- Javascript ---
#
# Vehicle.prototype.initialize
# Vehicle.num = 3
#
# class Car < Vehicle
# def initialize
# end
#
car = Car.new "black"
car1 = Car.new "grey"
car2 = Car.new "green"
car3 = Car.new "green"
veh = Vehicle.new "green"
# p Vehicle::num
puts car3.run()
# p car.is_black?
# p car1.is_black?
# p car.color
# car.color = "grey"
# p car.color
# p car.size