The new assignment operator =>
Version 3.0 introduces Pattern matching, and in particular the rightward assignment operator.
Useful after a long expression in a console or perhaps with a if else
block to improve indentation.
This has the advantage of reading the code in the same order of execution, with the assignment being made at the end. The possibility of writing the assignment on the next line has been abandoned, but you can still use \
.
⚠️ This is not the equivalent of the =
operator. =>
does not return a value. In the case of multiple assignment, an exception is thrown (as in Python) if the number of elements does not match. Does not allow assignment to an array.
Now waiting for the downward assignment ?! https://bugs.ruby-lang.org/issues/17768
Link to Ruby documentation for pattern matching
.