When using a private attr_accessor, why does self.attribute= work, but self.attribute doesn't?

Viewed 1291

Suppose I have a class where I define an attr_accessor like so:

private

attr_accessor :attribute

I understand why using the self.attribute reader method doesn't work - in Ruby you can't call a private method on an explicit receiver.

What I'm confused by is why doesn't this rule apply to the writer? Why can I call self.attribute = 1, and that doesn't throw any access violation errors?

1 Answers
Related