Hi,
When you use the word “private” to clear private methods - what does it
mean that only code within the object’s methods can access those private
methods? Can someone give me a simple example of this?
Thanks!
Hi,
When you use the word “private” to clear private methods - what does it
mean that only code within the object’s methods can access those private
methods? Can someone give me a simple example of this?
Thanks!
On Tue, Feb 15, 2011 at 10:22 AM, Gaba L.
[email protected] wrote:
When you use the word “private” to clear private methods - what does it
mean that only code within the object’s methods can access those private
methods? Can someone give me a simple example of this?
That’s basically correct, yes. Technically it means that the method
cannot be called with an explicit receiver:
class Foo
def pub
return “public method”
end
def call_priv
priv
end
def call_priv_explicitly
self.priv
end
private
def priv
return “private method”
end
end
f = Foo.new
f.pub
f.priv
f.call_priv
f.call_priv_explicitly
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs