Re: Private methods - only available to oneself?
- From: James Byrne <byrnejb@xxxxxxxxxxxxx>
- Date: Sat, 25 Feb 2006 04:51:16 +0900
Hal Fulton wrote:
Minkoo Seo wrote:
Thanks, Erik. I'm afraid that I'm not a native English spearker, so
sometimes it's not easy to express my own idea in exact English
expression.
Of course, I did look up the reference and found what instance_eval
does when being called. What I tried to ask was, as you stated,
"If we can do this, what's the purpose of 'protected' or 'private'?"
'private' is not like a locked door. It is like a sign saying "Do Not
Enter.'
Or look at it this way: It makes it "more difficult" to access private
vars (so that you will know you shouldn't), but doesn't make it
impossible (in case you really, really need to).
Hal
I do not understand why within the class definiton the Ruby interpreter
distinguishes between implicit and explict calls to self.
i.e
Class Foo
def foo_one
bar
end
def foo_two
self.bar
end
def bar
puts "In Bar"
end
private :bar
end
f = Foo.new
f.foo_one
-> "In Bar"
f.foo_two
-> NoMethodError: private method `bar' called for
This leads to the inference that self !=== <implicit self> which strikes
me as decidedly odd. Self is either always self or it is not and if not
then what is it? Whether self is declared as the the receiver or left
for the interpreter to contextually establish should make no difference
to the effect of a private method. Is this difference due to a parsing
limitation or a purposeful design decision that serves some intent I
cannot presently fathom? If the latter, then what is the purpose served
by this disticntion between an explicit and implicit self receiver?
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Private methods - only available to oneself?
- From: Jim Weirich
- Re: Private methods - only available to oneself?
- From: E. Saynatkari
- Re: Private methods - only available to oneself?
- From: dblack
- Re: Private methods - only available to oneself?
- References:
- Private methods - only available to oneself?
- From: minkoo.seo@xxxxxxxxx
- Re: Private methods - only available to oneself?
- From: Erik Veenstra
- Re: Private methods - only available to oneself?
- From: Minkoo Seo
- Re: Private methods - only available to oneself?
- From: Phrogz
- Re: Private methods - only available to oneself?
- From: Erik Veenstra
- Re: Private methods - only available to oneself?
- From: Minkoo Seo
- Re: Private methods - only available to oneself?
- From: Erik Veenstra
- Re: Private methods - only available to oneself?
- From: Minkoo Seo
- Re: Private methods - only available to oneself?
- From: Hal Fulton
- Private methods - only available to oneself?
- Prev by Date: Re: Net::HTTP and submitting forms
- Next by Date: Re: Private methods - only available to oneself?
- Previous by thread: Re: Private methods - only available to oneself?
- Next by thread: Re: Private methods - only available to oneself?
- Index(es):
Relevant Pages
|