H
hemant
##Won't work method #1
class Foobar
private
def foo; p "Foobar"; end
end
class Baz < Foobar
def blah; foo; end
end
baz =3D Baz.new
baz.foo
## Work method #2
class Foobar
private
def foo; p "Foobar"; end
end
class Baz < Foobar
def blah; foo; end
end
baz =3D Baz.new
baz.blah
PickAxe2:
If a method is private, it may be called only within the context of
the calling object=97it is never possible to access another object's
private methods directly, even if the object is of the same class as
the caller.
So what happens in Method#2, why foo can be easily called, when called
from inside the class Baz? I mean, that method foo should be still
bound to instance baz...so in which context foo gets called in
Method#2.
--=20
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.
class Foobar
private
def foo; p "Foobar"; end
end
class Baz < Foobar
def blah; foo; end
end
baz =3D Baz.new
baz.foo
## Work method #2
class Foobar
private
def foo; p "Foobar"; end
end
class Baz < Foobar
def blah; foo; end
end
baz =3D Baz.new
baz.blah
PickAxe2:
If a method is private, it may be called only within the context of
the calling object=97it is never possible to access another object's
private methods directly, even if the object is of the same class as
the caller.
So what happens in Method#2, why foo can be easily called, when called
from inside the class Baz? I mean, that method foo should be still
bound to instance baz...so in which context foo gets called in
Method#2.
--=20
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.