Skip to content

Commit 8310526

Browse files
committed
Update README.md
1 parent bcfb955 commit 8310526

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,16 @@ is_vowel? 'b'
14461446
14471447
A class method is a class-level method. There are multiple ways of defining a class method.
14481448
1449+
When a method is defined outside of the class definition, the method is marked as private by default. On the other hand,
1450+
the methods defined in the class definition are marked as public by default. The default visibility and the private mark
1451+
of the methods can be changed by public or private of the Module.
1452+
1453+
Whenever you want to access a method of a class, you first need to instantiate the class. Then, using the object,
1454+
you can access any member of the class.
1455+
1456+
Ruby gives you a way to access a method without instantiating a class.
1457+
Let us see how a class method is declared and accessed −
1458+
14491459
```ruby
14501460
class Mobile
14511461
def self.ring
@@ -1477,8 +1487,10 @@ end
14771487
14781488
Mobile.ring
14791489
```
1490+
To access this method, you need not create objects of the class Mobile.
14801491
1481-
A class method is an instance method of the class object. When a new class is created, an object of type `Class` is initialized and assigned to a global constant (Mobile in this case).
1492+
A class method is an instance method of the class object. When a new class is created, an object of type `Class` is
1493+
initialized and assigned to a global constant (Mobile in this case).
14821494
14831495
```ruby
14841496
Mobile = Class.new do

0 commit comments

Comments
 (0)