Name
Assignment
Synopsis
target
=expr
The following elements may assign targets:
- Global variables
Assignment to global variables alters global status. It isn’t recommended to use (or abuse) global variables. They make programs cryptic.
- Local variables
Assignment to uninitialized local variables also serves as variable declaration. The variables start to exist until the end of the current scope is reached. The lifetime of local variables is determined when Ruby parses the program.
- Constants
Assignment to constants may not appear within a method body. In Ruby, re-assignment to constants isn’t prohibited, but it does raise a warning.
- Attributes
Attributes take the following form:
expr.attr
Assignment to attributes calls the
attr
=
method of the result ofexpr
.- Elements
Elements take the following form:
expr
[arg
...]Assignment to elements calls the
[]=
method of the result ofexpr
.
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.