Introduction

The opposite of the private keyword is public.

You could put private before one method, but then revert back to public methods again afterwards using public, like so:

class Person 
  def anyone_can_access_this 
    ... 
  end 

  private 
  def this_is_private 
    ... 
  end 

  public 
  def another_public_method 
    ... 
  end 
end 

You can use private as a command by passing in symbols representing the methods you want to keep private, like so:

class Person 
  def anyone_can_access_this; ...; end 

  def this_is_private; ...; end 

  def this_is_also_private; ...; end 

  def another_public_method; ...; end 

  private :this_is_private, :this_is_also_private 
end 

The command tells Ruby that this_is_private and this_is_also_private are to be made into private methods.

Related Topic