Why the difference in treatment between the explict self reciever and
the implict self receiver?
Private methods are not allowed to have an explicit receiver
(using the ‘self’ there is like going out of the object and
then sending the message). The only exception to this rule
are writer methods (def foo=(); …; end) because without
the self., foo = x is always interpreted as an assignment
to a local variable.
Private methods are not allowed to have an explicit receiver
(using the ‘self’ there is like going out of the object and
then sending the message). The only exception to this rule
are writer methods (def foo=(); …; end) because without
the self., foo = x is always interpreted as an assignment
to a local variable.
E
Curious that this restriction does not appear to be mentioned in the
Pickaxe book. It also seems, to me, somewhat counter-intuitive. Is it
purposeful behaviour or an artifact of a stylistic convention?
Curious that this restriction does not appear to be mentioned in the
Pickaxe book. It also seems, to me, somewhat counter-intuitive. Is it
purposeful behaviour or an artifact of a stylistic convention?
Regards,
Jim
Page 35 in the 2nd Edition: “Private methods cannot be called with an
explicit receiverâ??the receiver is always self. This means that private
methods can be called only in the context of the current object; you
canâ??t invoke another objectâ??s private methods.”
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.