Unlike methods having different levels of visibility, Ruby instance variables are always private (from outside of objects). However, inside objects instance variables are always accessible, either from parent, child class, or included modules.
Since there probably is no way to alter how Ruby access @x
, I don't think you could have any control over it. Writing @x
would just directly pick that instance variable, and since Ruby doesn't provide visibility control over variables, live with it I guess.
As @marcgg says, if you don't want derived classes to touch your instance variables, don't use it at all or find a clever way to hide it from seeing by derived classes.