-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhead_first_ruby_methods_classes2.rb
42 lines (28 loc) · 1.85 KB
/
head_first_ruby_methods_classes2.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
#Designing a class
#benefit of using objects is they keep a set of data & the methods that operate
#on that data in one place
#To create an object you're going to need classes
#Class is a blueprint for making objects
#When use a class to make an object, the class describes what the object knows
#about itself,as well as what that object does
#Things an object knows about itself are called: Instance variables
#variables that belong to one object, comprise of everything the object knows about
#itself. Represent the object's state (its data) & can have differentt values for each instance
#of the class
#Things an object does are called: Instance methods
#methods that you call directly on that object. Comprise of what the object does.
#Have access to the object's variables & use them to change their behaviour based
#on the values in those classes
#User knows: name, password -Instance Variables
#User does: subscribe, login -Instance methods
#Instance of a class is an object made using that class. Only have to write one class
#but you can make many instances of that class
#Instance is another way of saying object
#If classes are cookie cutters, objects are the cookies they make
#example- dog class
#Instance variables (state): name , age
#Instance methods (behaviour): talk, move, report_age
#RubyMonstas
#Classes are like ideas, objects are concrete things, manifestations of their ideas.
#“[Smalltalk’s] way of making objects is quite Platonic in that some of them act as […] Ideas from which manifestations can be created. That the Ideas are themselves manifestations (of the Idea-Idea) and that the Idea-Idea is a-kind-of Manifestation-Idea — which is a-kind-of itself, so that the system is completely self-describing — would have been appreciated by Plato as an extremely practical joke.” — Alan C. Kay
#Encapsulation (see animals)