------art_50546_23844493.1213535885920
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Sun, Jun 15, 2008 at 11:03 PM, David A. Black <dblack / rubypal.com> wrote:

> Hi --
> On Sun, 15 Jun 2008, Florian Gilcher wrote:
>
>  -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>>
>> On Jun 15, 2008, at 12:37 PM, Greg Hauptmann wrote:
>>
>>  (complete email)Hi,
>>>
>>> Why can't an instance instantiated within a class method access a
>>> protected
>>> instance method?
>>>
>>> e.g.
>>>
>>> class Recurring < ActiveRecord::Base
>>>
>>> def self.reconcile rs  ecurring.find(:all)
>>> rs.each do |r|
>>> r.reconcile_one
>>> end
>>> end
>>>
>>> protected
>>>
>>> def reconcile_one
>>>   # do something
>>> end
>>>
>>> end
>>>
>>
>> Because calling a Method with an explicit receiver is like "calling from
>> the outside".
>>
>
> It's not quite that. Protected methods can be called with an explicit
> receiver, but they can only be called on objects that are of the same
> class as self (or a subclass thereof). In self.reconcile, self is
> Recurring, and therefore of class Class, while rs is of class
> Recurring.
>
>
> David


Thanks - can I ask:
(a) what do you mean by "explicit" - just to understand
(b) is there a way I can adjust my code so that I can leave methods like
"reconcile_one" private or protected, i.e. not really to be available to the
outside world (except in this case where I'm calling it from with an
instance of the class really, but it's just the logistics of Ruby that isn't
allowing it to work...if I've understood things correctly)

Greg

------art_50546_23844493.1213535885920--