-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearnings_chapter3.rb
26 lines (14 loc) · 1.21 KB
/
learnings_chapter3.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
#Inheritance
#Inheritance lets a subclass inherit methods from a superclass.
#A subclass can define its own methods in addition to the methods it inherits.
#A subclass can override inherited methods, replacing them with its own version.
#Bullet points
#Any ordinary Ruby class can be used as a superclass
#To define a subclass, simply specify a superclass in the class definition.
#Instance variables are not inherited from a superclass, but the methods that create & access instance variables are inherited.
#The super keyword can be used within a subclass method to call the overriden method of the same name on the superclass.
#If you don't specify arguments to the super keyword, it takes all arguments that the subclass method was called with, and psases them on to the superclass method.
#The expression value of the super keyword is the return value of the superclass method it calls.
#When you define a class, Ruby implicitly sets the Object class as the superclass, unless you specify one.
#Almost every Ruby object has instance methods from the Object class, inherited either directly or through another superclass.
#The to_s methods, instance_variables, and class methods are all inherited from the object class.