|
Re: Q) about singleton methods and access control: msg#01220lang.ruby.general
"Bennett, Patrick" wrote .... > Hmmm... doesn't make much sense to my C++ mind and freshly battered Ruby mind, but I'll accept it. > Thanks for the help guys (Christoph, Kent). I'll use the 'send' hack for now. :> One thing to keep in mind - is that C++'s and Ruby's ``protected access controls'' are related put ``private access controls" are totally different animals - e.g. --- class A { public: void use_private_meth1() { this -> private_meth(); } void use_private_meth2(A &b) { b.private_meth(); } private: void private_meth() {} }; int main() { A a,b; a.use_private_meth1(); a.use_private_meth2(b); return 1; }; --- compiles and runs just fine, but Ruby will choose the exception variants in a similar situation. --- class A def use_private_meth1 self.private_meth end def use_private_meth2(b) b.private_meth() end private def private_meth end end a,b = A.new,A.new begin a.use_private_meth1() rescue NameError => mes puts mes end begin a.use_private_meth2(b) rescue NameError => mes puts mes end --- /Christoph
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: JRuby beta 1.6/0.5.1, Hal E. Fulton |
|---|---|
| Next by Date: | Bug fix for html/fillinform, Philip Mak |
| Previous by Thread: | RE: Q) about singleton methods and access control, Bennett, Patrick |
| Next by Thread: | To be a Module, or not to be..., Holden Glova |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |