Access Specifier Ruby
Access Specifier in Ruby
It is determined dynamically, as the program runs, not statically. You will get an access violation only when the code attempts to execute the restricted method. You specify access levels to methods within class or module definitions using one or more of the three functions public, protected, and private.
Types of Access Specifier in Ruby
There are three types of Access Specifier in Ruby:
i. Public: These methods can be called by anyone—no access control is enforced. Methods are public by default (except for initializing, which is always private).
ii. Protected: These methods can be invoked only by objects of the defining class and its subclasses. Access is kept within the family.
iii. Private: These methods cannot be called with an explicit receiver—the receiver is always the current object, also known as self. It means that private methods can be called only in the context of the current object, you can’t invoke another object’s private methods.