A quick tip to how to define a class method as a private method, I have seen a lot of people doing it the wrong way. Let’s take a quick look on how to define a private instance method in Ruby
In the above code, poop is a public method and bark is a private method. If you are calling a public method it will be something like:
But calling a private method will give you an error.
Now define private class method is not as it is for instance method. They don’t exist as normally as instance methods are there but still, they exist.
if you want to define a class method private, let’s try it the way instance method works,
Oops, a private class method has been called :(. This is because the way Ruby defines the class methods, the self is actually Dog and the private method scope was never considered when Ruby was defining this method as a class method. Here are a couple of ways you can define a class method as private.
Quick way and easiest way to define a class method as private.
2. Using self as block
Block of class methods :)
Good luck ;)