Search code examples
ruby-on-railsrubyprivateprotected

Using private and protected methods in one controller in Rails


All the articles say about the difference between private and protected methods, however there's no clearance about using it.

So if code something like:

private
  def my_method
    #some code
  end

Does private affect only the my_method or everything below?

UPDATE: And if affects everything what if I want to use protected methods as well? If I code below my_method:

protected
  def another_method
    #some code
  end

Does it mean that private method has ended and protected methods section has started?


Solution

  • To simply answer your question: yes, when you have the following code:

    private
      ....
    
    protected
      ....
    

    Then private stops where protected begins.