Learn
Object-Oriented Programming II

Going Public

Great work! Now we'll get into the details of public and private methods.

Methods are public by default in Ruby, so if you don't specify public or private, your methods will be public. In this case, however, we want to make it clear to people reading our code which methods are public. We do this by putting public before our method definitions, like so:

class ClassName
  # Some class stuff
  public
  def public_method
    # public_method stuff
  end
end

Note that everything after the public keyword through the end of the class definition will now be public unless we say otherwise. (We'll say otherwise in the next exercise.)

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.