The purpose of private methods and when to use them

Before I describe my conception of private methods, I’ll discuss some of the wrong answers you can easily find online in hopes of inoculating you against their wrongness.As of this writing, if I google for “purpose of private methods” and click on the first result, the following Stack Overflow answer comes up highlighted:Private methods are useful for breaking tasks up into smaller parts, or for preventing duplication of code which is needed often by other methods in a class, but should not be called outside of that class.It can’t be said that the reason for the existence of private methods is to break up tasks into smaller parts or prevent duplication, because both those things can be achieved with public methods. This answer is wrong.Here’s another wrong answer, from the top answer on the second link on Google:Private methods are typically used when several methods need to do the exact same work as part of their responsibility (like notifying external observers that the object has changed), or when a method is split in smaller steps for readability.This is basically the same answer as the first, and it’s of course wrong for the same reason.
The purpose of private methods and when to use them #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/the-purpose-of-private-methods-and-when-to-use-them

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles