logo       

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

lang.ruby.general

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


"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

---
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
# 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 ...


/Christoph





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

News | FAQ | advertise