logo       

Re: Q) about singleton methods and access control: msg#01155

lang.ruby.general

Subject: Re: Q) about singleton methods and access control



Christoph wrote:

"Bennett, Patrick" wrote
....

Maybe I'm missing something here, but.... I called it from an instance.
You saw the 'testObj = A.new' - right?


No, the call is on the ``class Level'' - for example I get

No it's not. I was calling testObj.xxxxx - that's definitely an "instance" level call. :\
Arrgggh....

---
in class_meth self = A with self.type = Class
in class_meth self is still = A with self.type = Class
in an_instance_method self = #<A:0x2789ad8> with self.type = A
---

when running

---
class A
def A.class_meth
puts "in class_meth self = #{self} with self.type = #{type}"
obj = A.new
puts "in class_meth self is still = #{self} with self.type = #{type}"
end


This example makes no sense to me at all. What exactly are you testing? Why would you think 'self' would change in the middle of a method?
Why aren't you calling an instance method of obj (that you created in the singleton method)? That's the whole point of this issue. The fact that
singleton's can't create an >instance< and call that >instance's< private >instance< method (as in C++) - since the singleton is technically a member of the class, and should
be able to workin within its security constraints. Apparently, Ruby just doesn't support it. Fine, I can live with it. I'm still curious as to 'why' though - since it's seems
to be an odd ommision.

# versus
def an_instance_method
puts "in an_instance_method self = #{self} with self.type = #{type}"
end
end

A.class_meth
inst = A.new
inst.an_instance_method
---


That works(!)... but why? (scratching head)
Why does send bypass access control?


Well it does, so just use it ...

I will..... thanks. :>
(even though it seems a strange hack)





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise