-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearning_chapter4.rb
29 lines (14 loc) · 1.37 KB
/
learning_chapter4.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
#Creating objects
#Ruby calls the "initialize" method on new instances of a class. You can use "initialize" to set up a new object's instance variables.
#Class methods can be invoked directly on a class, rather than an instance of that class. They're great as factory methods.
#Bullet points
#Number literals with a decimal point will be treated as Float instances. Without a decimal point, they'll be treated as Fixnum instances.
#If either operand in a mathematical operation is a Float, the result of a Float.
#The format method uses format sequences to insert formatted values into a string.
#The format sequence type indicates the type of value that will be inserted. There are types for floating-point numbers, integers, strings, and more.
#The format sequence width determines the number of characters that a formatted value will take up within the string.
#The value nil represents nothing - the absence of a value.
#Operators such as +, -, *, and / are implemented as methods in Ruby. When an operator is encountered in your code, it's converted into a method call.
#Within insance methods, the self keyword refers to the instance that the method is being called on.
#If you don't specify a receiver when calling an instance method, the receiver defaults to self.
#Within a class body, you can use either def ClassName.method_name or def self.method_name to define a class method.