|
RE: Q) about singleton methods and access control: msg#01148lang.ruby.general
Christoph <chr_news@xxxxxxx> wrote in message >>"Bennett, Patrick" <Patrick.Bennett@xxxxxxxx> wrote in message >> This is what I'd "like" to do: >> class A >> >> def initialize() >> @varInternalOnly = 'test' >> end >> >> def A.createSpecialA() >> testObj = A.new >> testObj.internalHelperMethod() >internalHelperMethod is an ``instance method'' not a Class method >(see below). Maybe I'm missing something here, but.... I called it from an instance. You saw the 'testObj = A.new' - right? ;> >Anyway, as the short term fix you can >simply write > > testObj.send(:internalHelperMethod) That works(!)... but why? (scratching head) Why does send bypass access control? >Note that C++ static (class) method are quite different to Ruby's class >methods I never expected them to be the same - I was just curious why a fairly 'obvious' (at least to me) situation like being able to have a static method create instances of the classes it's defined in and access private methods wasn't supported in Ruby. Cheers, Patrick Bennett
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Q) about singleton methods and access control, Christoph |
|---|---|
| Next by Date: | Re: FXRuby usage: Capturing results from an FXDialogBox, Lyle Johnson |
| Previous by Thread: | Re: Q) about singleton methods and access control, Christoph |
| Next by Thread: | Re: Q) about singleton methods and access control, Christoph |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |