I see in ruby classes some people using _
prefix to define instance variables like @_property
while in normal condition attr_writer
uses the normal name like @property
to define instance variables.
What is the point of doing this and what is the difference?
The _
prefix isn't a language feature, it doesn't do anything special, it is just a convention.
In most cases, the developer wants to indicate that a variable is not in use, for example, a block variable that is not used in a block. Or they want to indicate that the variable is an internal variable of a module or gem and that others should not read or modify this variable directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With