0
I’m studying Ruby and arrived at the access control part. I had studied before access control in Java, then I thought it would be the same, but to my surprise, the statement private
and protected
are totally different in language Ruby.
My question is, how exactly private
and protected
work in the Ruby and why the Ruby not accept I call a private method using self
?
class Teste
def call_private
self.private_method # Se eu tirar o "self" ele funciona.
end
private
def private_method
puts "PRIVADO"
end
end
teste = Teste.new
teste.call_private
Another thing I just realized, is that if I define my method call_private
after the method private_method
, Ruby informs me that I’m trying to call a private method.
This means that all method below the statement private
are private ? If so, is there any way to create public methods below private methods ?