Don't declare private function on top of class
I find that some people are declaring private function at the top of class, like this
class SomeClass
private
def private_function
# some stuff
end
def public_function
# some stuff
end
end
Well, if you do like that then the public_function
defined below the private
key word is also a private! Duh!!.
A remedy would be to do something like this
class SomeClass
private
def private_function
# some stuff
end
public
def public_function
# some stuff
end
end
That is as soon a private function(s) definition(s) ends you can call public
thus making all functions that follow it public. But, though it’s right, it would be better to design an class like this
class ClassHowFunctionsCouldBePlaced
# put all public functions here
def public_function
end
protected
# put all protected functions here
def protected_function
end
private
# put all private functions here
def private_function
end
end
If you put functions as class ClassHowFunctionsCouldBePlaced
is defined, then you will have no access problems or other access issues.