The following code prints NoMethodError
. I don't understand the reason . Though the method i am calling is private but i am calling it from within the class.Can't a class var access it's private variable/function ?. I could do this in Java.
class Tester
private
def func_pri
puts("From a private function")
end
protected
def func_prot
puts("From a protected function")
end
public
def func_pub
puts("From a public function")
end
public
def caller(object)
object.func_pub
object.func_pri # This statement causes error
object.func_prot
end
end
o = Tester.new
o.caller(o)