Different ways to invoke a method in Ruby

  1. (Single run time) Using dot notation and calling the method on the object:
  2. (Persist name of method to database) Using send method:
  3. Get the method and call it like a Proc:
  4. Not good practice but useful sometimes. (Self-modifying method code):

Limit a method’s access in Ruby

To limit a method’s access we use 3 methods: private, protected and public.
Public: By default all methods defined are public. All instances of a class can use these public methods. Public methods are called with a explicit receiver.
Private methods are the ones defined under the private keyword and they can only be used within the class definition. The receiver in private methods is self. We use private methods for internal usage without a receiver.
Protected methods are similar to private with addition that it can be called with or without an explicit receiver but that receiver is always self or an object that inherit from self. We use protected methods defined as self.my_method for internal usage in other classes whenever inheritance isn’t used.