MyTetra Share
Делитесь знаниями!
Class Methods
Время создания: 31.08.2017 21:03
Текстовые метки: knowledge
Раздел: Ruby
Запись: xintrea/mytetra_db_mcold/master/base/15005423178dwl4quawz/text.html на

When a method is defined outside of the class definition, the method is marked as privateby default. On the other hand, the methods defined in the class definition are marked as public by default. The default visibility and the private mark of the methods can be changed by public or private of the Module.

Whenever you want to access a method of a class, you first need to instantiate the class. Then, using the object, you can access any member of the class.

Ruby gives you a way to access a method without instantiating a class. Let us see how a class method is declared and accessed −

class Accounts

def reading_charge


def Accounts.return_date



See how the method return_date is declared. It is declared with the class name followed by a period, which is followed by the name of the method. You can access this class method directly as follows −


To access this method, you need not create objects of the class Accounts.

Так же в этом разделе:
MyTetra Share v.0.58
Яндекс индекс цитирования